File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Comparing Strings in Arraylist and then making changes in the list

 
Siddhesh Khedekar
Ranch Hand
Posts: 42
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Experts,

I have an ArrayList of String.

I want to compare every String with all the other Strings in the ArrayList, if that string matches with one of the String in ArrayList then I want to make some changes to that particular String.

Could you please suggest how to go about it?
 
Mohamed Sanaulla
Saloon Keeper
Pie
Posts: 3159
33
Google App Engine Java Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you try implementing this? You can use equals() method of String class.
 
Rob Spoor
Sheriff
Pie
Posts: 20372
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siddhesh Khedekar wrote:then I want to make some changes to that particular String.

Do you mean you want to change the String at a specific List index? Because you know you can't change Strings themselves, right? Only references to it, including being a List element.

I suggest you look at ListIterator (and List.listIterator()). With it you can iterate over the List, then call set to change the value without having to worry about a nasty ConcurrentModificationException.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic