File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ package module4 .equals .lists ;
2+
3+ import java .util .ArrayList ;
4+
5+ public class TesteArrayListEquals {
6+
7+ /*
8+ * Essa aula exemplifica o uso do metodo contains();.
9+ * O método contains() internamente usa o método equals() para verificar se o conteúdo dentro de um objeto já existe na lista.
10+ * O método equals() é sobrescrito para fazer sentido a nossa lógica de negócio e verificar se duas contas já possuem dados iguals.
11+ * */
12+
13+ public static void main (String [] args ) {
14+
15+ ArrayList <String > lista = new ArrayList <>();
16+
17+ String nome = new String ("emanoel" );
18+ lista .add (nome );
19+
20+ String sobrenome = new String ("campos" );
21+ lista .add (sobrenome );
22+
23+ String nomeIgual = new String ("emanoel" );
24+
25+ boolean igual = nome .equals (sobrenome );
26+ System .out .println (igual );
27+
28+ boolean existe = lista .contains (nomeIgual );
29+ System .out .println (existe );
30+
31+ for (String nomes : lista ) {
32+ System .out .println (nomes );
33+ }
34+ }
35+ }
You can’t perform that action at this time.
0 commit comments