File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Performance and the fly likes ArrayList versus plain ol' String[] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Performance
Bookmark "ArrayList versus plain ol Watch "ArrayList versus plain ol New topic

ArrayList versus plain ol' String[]

Jason Barraclough

Joined: Aug 19, 2013
Posts: 5
Hiya folks at the ranch.

I have a problem that is baffling me...

firstnameList is an ArrayList<String>() object.
The above serialised array firstNamesArray is read in from a file. It is 105735 elements in size. When I convert it to an ArrayList object, it mysteriously drops down to 87268 strings in the list.

Plenty of JVM memory left over... I can create as many ArrayList objects of this 87268 String capacity but can't seem to create more than that. I need to incorporate up to 1,555,000 Strings in the list.

Any ideas what might be going on here?
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13035
Pretty mysterious alright.

Why are you sure the file contains 105735 String objects. What serialized that String[]?

Matthew Brown

Joined: Apr 06, 2010
Posts: 4542

Just to add to what William said: have you printed out firstNamesArray.length in that code to confirm the length?
I agree. Here's the link:
subject: ArrayList versus plain ol' String[]
It's not a secret anymore!