Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to add an element to an array without specifying index?

807600Nov 13 2007 — edited Nov 13 2007
Hello,

I would like to know how to add elements to an array of a specified size without specifying their indices. For example,
int[] newArr = new int[5];

newArr[] = 4;
newArr[] = 6;
This means I want newArr to look like this:
[4][6][ ][ ][ ]
This does not work, even though it does in other languages such as PHP. Can anyone tell me how to do this in Java? I would appreciate it!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 11 2007
Added on Nov 13 2007
5 comments
1,014 views