aspose file tools
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
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply 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: 31
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
Bartender

Joined: Sep 08, 2007
Posts: 2946
    
  15

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: 19232

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
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
 
Similar Threads
Sorting it out
Test for all empty Strings in LinkedHashMap<String,ArrayList<String>
List list = new ArrayList()
Converting String to ArrayList
splitting arrays