Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ListIterator problem

Status
Not open for further replies.

shaolinf

Programmer
Nov 20, 2007
14
GB
Hi guys,

Im using a vector to store my data and when I want to print it, it outputs the following:

FT@19821f
FT@addbf1

Here is the method and the call:

Method in directory class:

public void display()
{
ListIterator vIter = vec.listIterator() ;
while ( vIter.hasNext() )
{
System.out.println( vIter.next() ) ;
}
}

Call from Main class:

Directory d = new Directory() ;

d.add( "myname",1 ) ;
d.add( "yourname",2) ;

d.display() ; // Output data
 
How about
Code:
System.out.println((String)(vIter.next()));
 
Difficult to guess without the code that adds the elements to the Vector, ie, the add() method. Are you adding the strings or the numbers?
 
I think I disagree. If it's a String, the toString method will return the String itself, not a hashcode.

Cheers,
Dian
 
@diancecht: Yes. If it's a string.

Conclusio: It's not a string.
Maybe it's not a Directory, but something else.
Data?

We know: Directory has a vector to store Data.
Directory has an add-Method (Sting, int) to ...? - maybe to store something at an specific index - maybe to store an Object which is generated on the fly in the add-Method:
Code:
add (String s, int i)
{
        vec.add (new Data (s, i)); 
}

If you would store simple Strings in the vector, you would use add (int index, Sting s) as Vector does - not the other way round, and you would start with 0, not 1.
And the method would print "myname\nyourname" - not a hashcode.

Maybe shaolinf switches the order of index and object in the add-Method, and maybe he's counting from 1 instead of 0.

But a Vector of Strings wouldn't print hashcodes.

Maybe I didn't get your argument. :)

don't visit my homepage:
 
That was exactly what I was trying to say: we need to see the add() method to know what's being added. And from the println out, it's not a String.

Cheers,
Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top