Win a copy of Terraform in Action this week in the Cloud 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

delete item in tree set

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, i know one is not supposed to subclass a java class unless it adds new and useful functionality, so forgive me, I am still learning. This class saves a list of actor (String) names in my application. It works well for this purpose and I can add a new actor name. I want to be able to delete a name, but when I do within this class using methods of TreeSet, it deletes every name. The class below, despite it naive representation, transfers the contents of a SER file to a TreeSet. The TreeSet is used to diplay the names in a JList of the main application.

 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't show how you delete an actor. If you just call remove(actorName), it shouldn't delete every actor in your set, but it also won't update your file of the serialized output.
 
Ranch Hand
Posts: 884
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why would you require a TreeSet for this? To take advantage of the sorting provided? If not, I thought an ArrayList would suffice, or since you're storing Strings, why not an array of String?

Anyway, did you call the remove(Object obj) method, or the clear() method? The latter will remove all your objects from the TreeSet.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic