Results 1 to 8 of 8
Thread: new array ?
- 10-02-2008, 07:09 AM #1
Member
- Join Date
- Sep 2008
- Posts
- 16
- Rep Power
- 0
- 10-02-2008, 07:50 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You should learn the basis about Java, this is simple thing actually.
Java Code:public class IntArray { public static void main(String[] args) { int temp = 0; // Dummy value int[] myArray; // Declaring an int type array myArray = new int[10]; // Initialize the array and reserver the space // for 10 elements. // Adding elements to the array for(int i = 0; i < myArray.length; i++) { temp += 5; myArray[i] = temp; } // Display elements for(int j = 0; j < myArray.length; j++) { System.out.println("Value of index " + j + " is " + myArray[j]); } } }
- 10-02-2008, 08:43 AM #3
Member
- Join Date
- Sep 2008
- Posts
- 16
- Rep Power
- 0
thanks for replying!
what if i don't know the size of my array and i just want to be able to add an arbitrary amount to it.
instead of freeing up a fixed size space, how would i go about this?
- 10-02-2008, 08:59 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You want to set the dynamic size. Arrays not allowed that, you have to follow another way. Read more about Java collections. There are lots of options.
- 10-02-2008, 04:44 PM #5
Senior Member
- Join Date
- Aug 2008
- Posts
- 384
- Rep Power
- 5
Use an java.util.ArrayList. How? Find it out yourself, no spoon feeding. ;)
I die a little on the inside...
Every time I get shot.
- 10-03-2008, 04:17 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Actually you have lots of choices, ArrayList is just a one of them. As Supamagier says, finding yourself is your duty. We'll help you, just have atry.
- 10-03-2008, 12:55 PM #7
Member
- Join Date
- Oct 2008
- Posts
- 24
- Rep Power
- 0
else use list. it would be easier
- 10-03-2008, 07:31 PM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Similar Threads
-
3 by 3 array
By fromme87 in forum New To JavaReplies: 5Last Post: 10-02-2008, 08:34 AM -
help with an array.
By f_the_cook in forum New To JavaReplies: 7Last Post: 06-03-2008, 04:05 AM -
Array Reflection: Multi Array Reflection
By Java Tip in forum java.langReplies: 0Last Post: 04-23-2008, 08:08 PM -
Would appreciate your help with 2d Array..
By cloudkicker in forum New To JavaReplies: 1Last Post: 02-11-2008, 02:34 PM -
2D array
By bluekswing in forum New To JavaReplies: 2Last Post: 01-15-2008, 05:57 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks