[JAVA] 9.JAVA涓殑Collection
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[JAVA] 9.JAVA涓殑Collection相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/ima' title='ima'>ima item 瀹炵幇 alt rto dex lang col
Iterable
杩欐牱灏卞彲浠ラ亶鍘嗕笖涓嶆毚闇插唴閮ㄦ垚鍛榠tems
Iterable闇€瑕佸疄鐜癐terator锛岃€孖terator闇€瑕佸疄鐜癶asNext鍜宯ext
import java.util.Iterator;
public class GenericList<T> implements Iterable<T> {
private T[] items = (T[]) new Object[10];
private int count;
public void push(T item) {
items[count++] = item;
}
public T get(int index) {
return items[index];
}
@Override
public Iterator<T> iterator() {
return new ListItertor(this);
}
private class ListItertor implements Iterator<T> {
private GenericList<T> list;
private int index;
public ListItertor(GenericList<T> list) {
this.list = list;
}
@Override
public boolean hasNext() {
return index < list.count;
}
@Override
public T next() {
return list.items[index++];
}
}
}
Hash Table
杩欎釜涓嶅睘浜嶪terable鎺ュ彛鐨勫疄鐜扮被
php涓殑foreach寰幆