-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMetodosArrayList.java
More file actions
58 lines (37 loc) · 1.43 KB
/
MetodosArrayList.java
File metadata and controls
58 lines (37 loc) · 1.43 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.ArrayList;
public class MetodosArrayList {
public static void main(String[] args) {
ArrayList<String> arrayList = new ArrayList();
arrayList.add("José");
arrayList.add("Maria");
arrayList.add("Ana");
arrayList.add("Sarah");
System.out.println(arrayList);
//Inclusão com index
arrayList.add(0,"João");
System.out.println(arrayList);
//Remoção por objeto
arrayList.remove("Maria");
System.out.println(arrayList);
//Remoção por index. Cuidado o Index deve ser válido.
arrayList.remove(1);
System.out.println(arrayList);
//Set ou replace
arrayList.set(2,"Nádia");
System.out.println(arrayList);
//IsEmpty retorno Boolean verifica se está vázio
System.out.println("Verifica se está vázio: " + arrayList.isEmpty());
// size - Retorno int
System.out.println("Tamanho do array: " + arrayList.size());
//Contains - verfica se existe conteúdo no objeto.
System.out.println("Conteins: " + arrayList.contains("Nádia"));
//Clear - limpa o array
arrayList.clear();
System.out.println(arrayList);
ArrayList one = new ArrayList();
ArrayList two = new ArrayList();
one.add(1);
two.add(1);
System.out.println("Comparação de arrays com equals: "+ one.equals(two));
}
}