aspose file tools*
The moose likes Beginning Java and the fly likes Vector remove element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector remove element" Watch "Vector remove element" New topic
Author

Vector remove element

supriya acharya
Greenhorn

Joined: Jan 26, 2009
Posts: 28
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

Joined: Feb 03, 2009
Posts: 44
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

Joined: Oct 13, 2005
Posts: 39435
    
  28
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

Joined: Jan 26, 2009
Posts: 28
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

Joined: Jul 26, 2007
Posts: 10451
    
    8

Nothing GUI related here.
Moving


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39435
    
  28
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

Joined: Jan 26, 2009
Posts: 28
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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector remove element