• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

Using Enhanced for-loop on Collection of "Mutable" Objects (such as StringBuilder)

 
Ranch Hand
Posts: 212
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I found the sample code below in one of the tutorials. Here while we are using the enhanced for loop, we are modifying the value of the stringbuilder but after that we are not adding the modified value back to the list, but the value of the stringbuilder present in the list is changed.  How? Pictorial representation would be helpful

 
Saloon Keeper
Posts: 11472
247
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you know what the difference is between mutable and immutable types?
 
Marshal
Posts: 68075
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also: do you know what the difference would be if you added immutable objects to the List:-
 
Good heavens! What have you done! Here, try to fix it with this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!