Skip to content

Commit f8c8a4c

Browse files
committed
uma forma diferente de manipular arrays
1 parent 4a6e0c4 commit f8c8a4c

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package module3.arrayslist.generics;
2+
3+
public class GuardadorDeString {
4+
5+
private String[] nomes;
6+
private int posicaoLivre;
7+
8+
public GuardadorDeString() {
9+
this.nomes = new String[10];
10+
this.posicaoLivre = 0;
11+
}
12+
13+
public void adiciona(String nome) {
14+
this.nomes[this.posicaoLivre] = nome;
15+
this.posicaoLivre++;
16+
}
17+
18+
public int getQuantidadeDeElementos() {
19+
return this.posicaoLivre;
20+
}
21+
22+
public String getReferencia(int posicao) {
23+
return this.nomes[posicao];
24+
}
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package module3.arrayslist.generics;
2+
3+
public class TestaGuardador {
4+
5+
public static void main(String[] args) {
6+
7+
GuardadorDeString guardadorDeString = new GuardadorDeString();
8+
9+
String nome = new String("emanoel");
10+
guardadorDeString.adiciona(nome);
11+
12+
String sobrenome = new String("campos");
13+
guardadorDeString.adiciona(sobrenome);
14+
15+
int tamanho = guardadorDeString.getQuantidadeDeElementos();
16+
System.out.println(tamanho);
17+
18+
String ref = guardadorDeString.getReferencia(0);
19+
String ref2 = guardadorDeString.getReferencia(1);
20+
21+
System.out.println(ref.length());
22+
System.out.println(ref2.toUpperCase());
23+
}
24+
}

0 commit comments

Comments
 (0)