wood burning stoves 2.0*
The moose likes Java in General and the fly likes Comparing Strings in Arraylist and then making changes in the list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Comparing Strings in Arraylist and then making changes in the list" Watch "Comparing Strings in Arraylist and then making changes in the list" New topic
Author

Comparing Strings in Arraylist and then making changes in the list

Siddhesh Khedekar
Ranch Hand

Joined: Nov 09, 2009
Posts: 36
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

Joined: Sep 08, 2007
Posts: 3068
    
  33

Did you try implementing this? You can use equals() method of String class.


Mohamed Sanaulla | My Blog
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Comparing Strings in Arraylist and then making changes in the list