Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Vector remove element

 
supriya acharya
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have vector containing 69 elements. And i am removing some elements from vector.But my code is not able to remove that element.

here is my code


deleted array contains indexes that are to be removed.output i am getting is

Messages vector size before deletion :69
Bool :false
Messages vector size after deletion :69

 
Bartek Myszkowski
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this:
http://java.sun.com/j2se/1.4.2/docs/api/java/util/Vector.html#remove(java.lang.Object)

Returns: true if the Vector contained the specified element.


so if You get false returned Vector simply doesn't contain element You want to remove.
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Read the API documentation for Vector, and see what it means when remove returns false.
Have a look at the remove method description. Try as a debugging exercise preceding that with

System.out.printf("The vector %s this message: %s.%n", messages.contains(deleted[i]) ? "does" : "does not", deleted[i]);//test

What format is deleted[i] in? Is it a message?
 
supriya acharya
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Read the API documentation for Vector, and see what it means when remove returns false.
Have a look at the remove method description. Try as a debugging exercise preceding that with

System.out.printf("The vector %s this message: %s.%n", messages.contains(deleted[i]) ? "does" : "does not", deleted[i]);//test

What format is deleted[i] in? Is it a message?




Thanks i have solved the problem
 
Maneesh Godbole
Saloon Keeper
Posts: 11027
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing GUI related here.
Moving
 
Campbell Ritchie
Sheriff
Pie
Posts: 48940
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
supriya acharya wrote:Thanks i have solved the problem
Well dont but how did you do it? Others can learn from your advice.
 
supriya acharya
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:
supriya acharya wrote:Thanks i have solved the problem
Well dont but how did you do it? Others can learn from your advice.



Actually i have used list itrator to list the elements in the array and problem was first i was doing messages.remove(deleted[i]) so it was searching for object deleted[i] which actually should messages.removeElementAt(deleted[i]) that means it will delete object at index indicated by deleted[i]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic