-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathExemple1.java
More file actions
34 lines (24 loc) · 896 Bytes
/
Exemple1.java
File metadata and controls
34 lines (24 loc) · 896 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
33
34
import java.util.ArrayList;
public class Exemple1 {
public static void main(String[] args) {
ArrayList<String> nomsAlumnes;
nomsAlumnes = new ArrayList<>();
nomsAlumnes.add("Andreu");
nomsAlumnes.add("Maria");
nomsAlumnes.add("Josep");
nomsAlumnes.add(0, "Helena");
nomsAlumnes.set(0, "Geni"); // Sobre escriu. Update
nomsAlumnes.remove("Geni"); // Delete
mostrarElementsArrayList(nomsAlumnes);
System.out.println("----");
}
private static void mostrarElementsArrayList(ArrayList<String> nomsAlumnes) {
for (int i = 0; i < nomsAlumnes.size(); i++) {
System.out.println(i + nomsAlumnes.get(i));
}
System.out.println("For-each");
for (String nom : nomsAlumnes) {
System.out.println(nom);
}
}
}