• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Comparing Strings in Arraylist and then making changes in the list

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you try implementing this? You can use equals() method of String class.
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic