-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
17
-
generic
-
generic
A DESCRIPTION OF THE PROBLEM :
// stack iterator starts from bottom of stack instead of top of stack
import java.util.Stack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
class Main {
public static void main(String[] args) {
Stack<Character> stack = new Stack<>();
Collection<Character> list = new ArrayList<>();
stack.push('a');
list.add('b');
stack.addAll(list);
Iterator stackIterator = stack.iterator();
// prints 'a' (bottom of stack) and not 'b' (top of stack)
System.out.println(stackIterator.next());
// prints 'b' (top of stack) and not 'a' (bottom of stack)
System.out.println(stackIterator.next());
}
}
// stack iterator starts from bottom of stack instead of top of stack
import java.util.Stack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
class Main {
public static void main(String[] args) {
Stack<Character> stack = new Stack<>();
Collection<Character> list = new ArrayList<>();
stack.push('a');
list.add('b');
stack.addAll(list);
Iterator stackIterator = stack.iterator();
// prints 'a' (bottom of stack) and not 'b' (top of stack)
System.out.println(stackIterator.next());
// prints 'b' (top of stack) and not 'a' (bottom of stack)
System.out.println(stackIterator.next());
}
}
- duplicates
-
JDK-4475301 RFE: java.util.Stack.iterator() iterates the wrong way
- Closed