Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
2D List Iterator
//'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_111 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { List<Integer> list1 = new ArrayList<>(Arrays.asList(1, 2)); List<Integer> list2 = new ArrayList<>(Arrays.asList(3)); List<List<Integer>> vec2d = new ArrayList<>(); vec2d.add(list1); vec2d.add(list2); //1,2 //3 ListOfListIterator<Integer> myIter = new ListOfListIterator<>(vec2d); System.out.println(myIter.hasNext()); System.out.println(myIter.next()); System.out.println(myIter.hasNext()); myIter.remove(); System.out.println(myIter.next()); for (int i = 0; i < vec2d.size(); i++) { if (vec2d.get(i) == null) continue; for (int j = 0; j < vec2d.get(i).size(); j++) { System.out.println("List" + i + ":" + vec2d.get(i).get(j)); } } System.out.println(myIter.hasNext()); System.out.println(myIter.next()); } } class ListOfListIterator<T> implements Iterator<T> { Iterator<List<T>> iter1; Iterator<T> iter2; public ListOfListIterator(List<List<T>> ListOfList) { iter1 = ListOfList.iterator(); iter2 = null; } public boolean hasNext() { while ((iter2 == null || !iter2.hasNext()) && iter1.hasNext()) iter2 = iter1.next().iterator(); return iter2 != null && iter2.hasNext(); } public T next() { //if (iter2 == null) throw new NoSuchElementException(); if (iter2 == null) throw new RuntimeException(); return iter2.next(); } public void remove() { //if (iter2 == null) throw new IllegalStateException(); if (iter2 == null) throw new RuntimeException(); iter2.remove(); } }
run
|
edit
|
history
|
help
0
Coding Challenge - 04 (Perfect numbers)
output1
[a-zA-Z ]{0,12}
square of array element
else weird
Решето Эратосфена
LunarLanding.java
MergeSort
Scope
calc exp ne