Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

String[] vs ArrayList, very simple

 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

VS

Thanks,
cc11rocks aka John Price
 
Pat Farrell
Rancher
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4678
7
Linux Mac OS X VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Already answered 4 days ago:

http://www.coderanch.com/t/536404/java/java/Converting-String-ArrayList
 
john price
Ranch Hand
Posts: 495
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you guys.
,
cc11rocks aka John Price
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13061
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic