Win a copy of Head First Android this week in the Android forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problem removing String and StringBuilder from an ArrayList

 
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am confused how remove works for string and stringbuilder objects in ArrayList...example

AND

can anyone please explain me.??i think its because remove() method implicitly calls equals() method and stringbuilder do not override equals method
 
Marshal
Posts: 5146
321
IntelliJ IDE Python Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Akshay, please try to write a meaningful subject for your questions. I edited it in this post because "ARRAYLIST1" doesn't mean anything to anyone.

I also fixed up your post to UseCodeTags properly. Looks a lot better now don't you think?
 
author & internet detective
Posts: 40797
829
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Akshay Rawal wrote:i think its because remove() method implicitly calls equals() method and stringbuilder do not override equals method


You are correct. Since they do not override equals(), the Object class' equals() method is used. Which is equivalent to ==.

You could remove the objects by index instead of object. Or maybe there is another approach if there is something you are trying to accomplish. (It looks like a learning exercise so maybe not.)
 
Akshay Rawal
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tim Cooke thanks for editing, next time i will take care of that..Jeanne Boyarsky thanks for confirmation
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why does StringBuffer/StringBuilder not override equals or hashCode? explains -

Because StringBuffer is mutable, and its primary use is for constructing strings.



Regards,
Dan
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic