ass*_*ias 63
Collection 是一个Iterable ......所以你可以这样写:
public static void main(String args[]) {
List<String> list = new ArrayList<String>();
list.add("a string");
Iterable<String> iterable = list;
for (String s : iterable) {
System.out.println(s);
}
}
Run Code Online (Sandbox Code Playgroud)
我不清楚你需要什么,所以:
这会让你成为一名迭代者
SortedSet<String> sortedSet = new TreeSet<String>();
Iterator<String> iterator = sortedSet.iterator();
Run Code Online (Sandbox Code Playgroud)
集合和列表是Iterables,这就是为什么你可以执行以下操作:
SortedSet<String> sortedSet = new TreeSet<String>();
Iterable<String> iterable = (Iterable<String>)sortedSet;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
75268 次 |
| 最近记录: |