Results 1 to 8 of 8
- 02-16-2009, 03:49 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 27
- Rep Power
- 0
-
Look up ArrayLists
- 02-16-2009, 05:51 AM #3
Yes, ArrayLists are what you are looking for. The only catch is that they must contain Objects. That means no primitives, e.i. no ints, longs, doubles, floats, bytes, chars, shorts, etc. If you wanted it to contain numbers, you will have to use the Object Wrappers for the primitives, i.e. Integer class, Double class, etc. Strings are Objects also if you were planning on putting those in the array. Unless you were planning on having different types of Objects in the ArrayList, i.e. index 0 is an Integer, object 1 is a String, object 2 a BigDecimal, etc., you should use generics, here is an example assuming that you are using Integers:
Hope this HelpedJava Code:import java.util.ArrayList; class ArrayListExample { public void doExample() { /* ArrayList size will automatically increase when you try to add another object and it is full. The argument int the ArrayList constructor used here is the initial size of the ArrayList. I believe if you just do () in- stead of (size), it will assign a default capacity of 10 */ ArrayList<Integer> aList = new ArrayList<Integer>(4); for(int i = 0; i < 18; i++) { aList.add(new Integer(i)); } aList.trimToSize(); // this deletes any empty spaces in the list, // but it doesnt do anything in this situation because our // list started out at size 4 and then each new Integer in- // creased the size by 1 int[] anArray = new int[aList.size()]; // put it into int array for(int i = 0; i < anArray.length; i++) { anArray[i] = aList.get(i).intValue(); } } }
-MK12Tell me if you want a cool Java logo avatar like mine and I'll make you one.
- 02-16-2009, 08:02 AM #4
Senior Member
- Join Date
- Dec 2008
- Posts
- 526
- Rep Power
- 0
St. Claus exists ) ddatta8 , you are lucky today ;)
MK12, I still recognize the generous person in the forum )))
- 02-16-2009, 11:36 AM #5
Member
- Join Date
- Dec 2008
- Posts
- 27
- Rep Power
- 0
Thanks a lot. It is very helpful.
- 02-16-2009, 02:58 PM #6
Webuser: :). ddata8: please go to the top of this page and click Thread Tools and then in the drop-down menu, click Mark This Thread As Solved, so no one wastes time going to this thread thinking that it hasn't been solved yet.
Tell me if you want a cool Java logo avatar like mine and I'll make you one.
- 04-08-2009, 03:54 AM #7
Member
- Join Date
- Apr 2009
- Posts
- 3
- Rep Power
- 0
I want to say hi
My name is Derek and
I'm glad to join to this forum.
-
Similar Threads
-
array passing dynamically
By jazz2k8 in forum Advanced JavaReplies: 2Last Post: 10-16-2008, 10:29 PM -
Dynamically changing the display
By abhiN in forum JavaServer Pages (JSP) and JSTLReplies: 1Last Post: 01-22-2008, 11:19 PM -
passing data dynamically
By abhiN in forum Advanced JavaReplies: 1Last Post: 01-22-2008, 09:43 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks