Help Needed

Reply

Join Date: Apr 2007
Posts: 1
Reputation: longihale is an unknown quantity at this point 
Solved Threads: 0
longihale longihale is offline Offline
Newbie Poster

Help Needed

 
0
  #1
Apr 26th, 2007
Okay I am trying to get an array (a primitive integer array) called a1 which contains integers. I want to return an ArrayList that has the entries of a1? This should be really simple, but it is just one of those days....

like

  1. public static ? formlist(//a1 is sent as a parameter so int a1[] ?)
  2. {
  3.  
  4. }
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 46
Reputation: lucky1981_iway is an unknown quantity at this point 
Solved Threads: 3
lucky1981_iway's Avatar
lucky1981_iway lucky1981_iway is offline Offline
Light Poster

Re: Help Needed

 
0
  #2
Apr 27th, 2007
For example you can do like this. It all depends on your requirments.
import java.util.ArrayList;
 
 
 
 

public class ArrayPass {
ArrayList<Integer> arraylist = new ArrayList<Integer>();
public ArrayList<Integer> MyArrayList(int [] a1)
{
for(Integer a : a1)
{
arraylist.add(a);
System.out.println(a);
} return arraylist;
}
public static void main(String [] args)
{
ArrayPass ap = new ArrayPass();
ArrayList<Integer> a = new ArrayList<Integer>();
int [] a1 = {1,2,3,4,5};
a = ap.MyArrayList(a1);
for(Integer b : a)
{
System.out.println(" after passing : "+ b);
}
}
}
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 854 | Replies: 1
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC