hi,
how can I make the size of the array is equal to the number of elements in the array
sk8ergirl
0
Newbie Poster
Recommended Answers
Jump to PostYou can't. An array size is fixed when it is created, and cannot be changed.
All you can do is to create a second array of the right size, copy all the entries into that one, point any reference variables to the new array, then allow the original array to …
Jump to PostHi, that's sort of a vague question. If you you have elements in the array then it already has a size. You can find the size of the array by using its length property. For instance:
int[] ary = new int[10]; int j=0; for (int i=0;i<ary.length;i++) { …
Jump to PostLike that, but with arrays. There's no point doing that with ArrayLists.
Jump to PostNow you know what needs to be done, you may want to look at the Arrays.copyOf method, which implements just what we were talking about.
All 13 Replies
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Stuugie
50
Marketing Strategist
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Stuugie
50
Marketing Strategist
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Stuugie
commented:
Thanks for helping with my helping confusion
+2
Stuugie
50
Marketing Strategist
Stuugie
50
Marketing Strategist
IIM
163
Master Poster
Stuugie
50
Marketing Strategist
sk8ergirl
0
Newbie Poster
sk8ergirl
0
Newbie Poster
Stuugie
50
Marketing Strategist
JamesCherrill
4,733
Most Valuable Poster
Team Colleague
Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.