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 PostI think sk8ergirl is referring to the problem where you have a (large) array that's not fully populated with actual data, so you want to "fit" the array to the number of elements that you have actually used.
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.