• 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

How to delete from List without distutbing the position of other objects.

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have a List from which i want to delete objects based on there position.

When i delete an Object from the list from say index :4 ,the list gets sorted and all the objects from below are shifted to upper index..
I mean i want the object to be deleted from the mentioned index ,but the shifting should not happen.

Is there any way to do this.

Please Help

Thanks
Sujai.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you delete item number 4 from a list, the old number 5 is moved down to become the new number 4. That's the definition of deleting an entry from the list.

If you'd like the list to contain a null (or an empty String, or whatever) at that position instead, then don't delete the item; just set that element to the contents you want -- i.e.,

theList.set(4, null);
 
See ya later boys, I think I'm in love. Oh wait, she's just a tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic