-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.java
More file actions
32 lines (24 loc) · 765 Bytes
/
list.java
File metadata and controls
32 lines (24 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package com.petehouston.tutorial.java;
import java.util.*;
public class TempClass {
public static void main(String[] args) {
List<Integer> list = new ArrayList<>();
list.add(8);
list.add(2);
list.add(4);
list.add(19);
Iterator<Integer> iterator = list.iterator();
while (iterator.hasNext()){
int element = iterator.next();
System.out.println(element);
}
for (Integer integer : list) {
System.out.println(integer);
}
List<String> names = List.of("John","Sarah","Jack");
for (Iterator<String> i = names.iterator(); i.hasNext();){
String name = (String) i.next();
System.out.println("Name = " + name);
}
}
}