S Keith

Greenhorn
+ Follow
since Feb 06, 2008
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by S Keith

Its all to do with the variables scope.

In java we can have the following types of variables:

instance variables
class variables
local variables

They have different scopes. Instance variables are 'alive' if the object they live in is alive.

Class variables are alive when the class is loaded.

Local variables are alive if the method they live in is still on the stack.

Parameters are local variables.

The variables you were referring to are local variables with the same names but in different methods, and different classes.




Theres more to this. Anyone have a link?
[ March 24, 2008: Message edited by: S Keith ]
16 years ago
Heres some code that should explain things.

I've tried to keep it similar to the code you gave.



running this gives:




http://java.sun.com/javase/6/docs/api/java/lang/String.html
16 years ago
howdy.

Can you give me your input file?

If you test it with



there is no problem.


This is exactly what i have in the file run0.java


and i get the output:


[ March 24, 2008: Message edited by: S Keith ]
16 years ago
I tried it with the file: foo, bar, baz

You have a call in making it appear that you have duplicates.

The call to will also stop you properly linking the list because the reference is tampered with, before the link field in is set.

if you move above the call, then that would fix the problem, and you will see that the whole list is printed twice.



if you take out:



then you will get your list printed ok

[ March 23, 2008: Message edited by: S Keith ]
[ March 23, 2008: Message edited by: S Keith ]
16 years ago