aspose file tools*
The moose likes Performance and the fly likes String[] vs ArrayList, very simple Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Performance
Bookmark "String[] vs ArrayList, very simple" Watch "String[] vs ArrayList, very simple" New topic
Author

String[] vs ArrayList, very simple

john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495


VS

Thanks,
cc11rocks aka John Price


“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” (Mosher's Law of Software Engineering)
“If debugging is the process of removing bugs, then programming must be the process of putting them in.” (Edsger Dijkstra)
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4639
    
    5

why would you ever care about such simple code?

Do you have a real question here?

If the lists are constants, I use the Google Guava ImmutableList classes, which have very nice initialization code. I don't care how long it takes the compiler to generate the code, its never executed more than once.
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

My question is which one is better for performance. I have 101 "bad words" that I am filtering for a chat client. I want to know which is better for performance. The above were just examples of the "setting up" for the words.
Thanks,
John Price aka cc11rocks
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18154
    
    8

It probably doesn't make the least bit of difference. Presumably the code you execute to do whatever you do with each word in the list will dwarf the code required to get the word out of the list.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4639
    
    5

john price wrote:My question is which one is better for performance.

There is nothing to have performance with in your sample code.

As others have written in other posts of yours, if you care about performance, you won't use either. You would use a Set. I would use one of the ImmutableSet classes from Guava. Probably a tree set, if you only have a few hundred entries.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2095
    
    7
Already answered 4 days ago:

http://www.coderanch.com/t/536404/java/java/Converting-String-ArrayList
john price
Ranch Hand

Joined: Feb 24, 2011
Posts: 495

Thank you guys.
,
cc11rocks aka John Price
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5
Personally - I would choose to initialize whatever structure by reading from a file rather than hard coding the words. It is only done once so spend an extra second for the sake of flexibility.

Bill

Java Resources at www.wbrogden.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String[] vs ArrayList, very simple
 
Similar Threads
Vector Vs Expandable Array
Comparator vs comparable
out.println vs. gui netbeans
Generic Object Types vs Generic References
Converting String to ArrayList