iterator problem
-
List<OrderedPair> list1 = new ArrayList<OrderedPair>() ;
OrderedPair e0 = new OrderedPair(); e0.index=0; e0.value=1; OrderedPair e1 = new OrderedPair(); e1.index=2; e1.value=2; OrderedPair e2 = new OrderedPair(); e2.index=3; e2.value=3; ListIterator<OrderedPair> iterator = list1.listIterator(); iterator.add(e0); iterator.add(e1); iterator.add(e2); OrderedPair op1 = (OrderedPair) iterator.previous(); System.out.print("index = "); System.out.print(op1.index); System.out.print(", value = "); System.out.print(op1.value); System.out.println(); OrderedPair op2 = (OrderedPair) iterator.previous(); System.out.print("index = "); System.out.print(op2.index); System.out.print(", value = "); System.out.print(op2.value); System.out.println(); OrderedPair op3 = (OrderedPair) iterator.previous(); System.out.print("index = "); System.out.print(op3.index); System.out.print(", value = "); System.out.print(op3.value); System.out.println();
Above is the code block which works fine on one system but the previous() method on some other system doesnt move the iterator backwards and results in the same object . Any idea why such a behaviour? Pritha
-
List<OrderedPair> list1 = new ArrayList<OrderedPair>() ;
OrderedPair e0 = new OrderedPair(); e0.index=0; e0.value=1; OrderedPair e1 = new OrderedPair(); e1.index=2; e1.value=2; OrderedPair e2 = new OrderedPair(); e2.index=3; e2.value=3; ListIterator<OrderedPair> iterator = list1.listIterator(); iterator.add(e0); iterator.add(e1); iterator.add(e2); OrderedPair op1 = (OrderedPair) iterator.previous(); System.out.print("index = "); System.out.print(op1.index); System.out.print(", value = "); System.out.print(op1.value); System.out.println(); OrderedPair op2 = (OrderedPair) iterator.previous(); System.out.print("index = "); System.out.print(op2.index); System.out.print(", value = "); System.out.print(op2.value); System.out.println(); OrderedPair op3 = (OrderedPair) iterator.previous(); System.out.print("index = "); System.out.print(op3.index); System.out.print(", value = "); System.out.print(op3.value); System.out.println();
Above is the code block which works fine on one system but the previous() method on some other system doesnt move the iterator backwards and results in the same object . Any idea why such a behaviour? Pritha
does that throw an exception? (NuSuchElementException) Why do you add via the iterator? you can add directly to the ArrayList. It might also be useful to OOP that code.
regards Torsten When I'm not working
-
does that throw an exception? (NuSuchElementException) Why do you add via the iterator? you can add directly to the ArrayList. It might also be useful to OOP that code.
regards Torsten When I'm not working
-
thanks for your reply it doesnt throw an exception. The problem is it works on one system and doesnt work on another. should i reinstall eclipse or java libraries. thanks
check the runtime, there might be the difference.
regards Torsten When I'm not working
-
check the runtime, there might be the difference.
regards Torsten When I'm not working
-
the java runtime. There is a java runtime on each machine. Those might be different versions and also 32bit or 64bit, which also can be acting different. Open a command prompt and type
java -version
. Latest version is V1.6.31, also good to go is V1.6.30. Version 1.6.29 hat a problem with the FileDialog under SWT/Jface.regards Torsten When I'm not working
-
the java runtime. There is a java runtime on each machine. Those might be different versions and also 32bit or 64bit, which also can be acting different. Open a command prompt and type
java -version
. Latest version is V1.6.31, also good to go is V1.6.30. Version 1.6.29 hat a problem with the FileDialog under SWT/Jface.regards Torsten When I'm not working
-
does that throw an exception? (NuSuchElementException) Why do you add via the iterator? you can add directly to the ArrayList. It might also be useful to OOP that code.
regards Torsten When I'm not working
TorstenH. wrote:
Why do you add via the iterator? you can add directly to the ArrayList.
Why are you so insistent on telling this guy how to build his application when you have no idea what his requirements are? There are perfectly valid reasons to insert via a ListIterator. That's why the method exists on the interface.
-
the java runtime. There is a java runtime on each machine. Those might be different versions and also 32bit or 64bit, which also can be acting different. Open a command prompt and type
java -version
. Latest version is V1.6.31, also good to go is V1.6.30. Version 1.6.29 hat a problem with the FileDialog under SWT/Jface.regards Torsten When I'm not working
check your development Java runtime envriment,exp:JDk1.5 hava the Iterator interface,but before this version,have no Iterator interface.I test the programe throught JRE1.6 of my dev computor,the follow is the message of console: aaaa index = 3, value = 3 index = 2, value = 2 index = 0, value = 1