//Iterator Iterator interface / / Determine whether there is content, if there is, take it out //Just use the iterator() of the Collection interface to instantiate the Iterator interface public static void main(String[] args) { List<Integer> arrayList = new ArrayList<Integer>(); arrayList.add(1); arrayList.add(2); arrayList.add(3); Iterator<Integer> iterator = arrayList.iterator();//Instantiate the Iterator interface while(iterator.hasNext()){//Determine whether there is content Integer integer = iterator.next(); System.out.println(integer); } //Iterator ListIterator interface, bidirectional output; output from front to back, from back to front //Remember, you must first, output from front to back before you can output from back to front ListIterator>Integer> listIterator = arrayList.listIterator (); while (listIterator.hasNext()) { Integer integer = listIterator.next(); System.out.print(integer+","); } System.out.println(); while (listIterator.hasPrevious()) { Integer previous = listIterator.previous(); System.out.print(previous+","); } }
Java class set. Iterator interface Iterator
Guess you like
Origin http://10.200.1.11:23101/article/api/json?id=327037486&siteId=291194637
Recommended
Ranking