Quantcast
Channel: Programação - GUJ
Viewing all articles
Browse latest Browse all 33093

Vetor não repetir objeto

$
0
0

@Splayer escreveu:

Estou tentando fazer com que um vetor não repita os valores, após isso verificar se existe variável, caso não, adiciona-la.

Set<String> dica = new HashSet<>();
String[] aux = {"Metais Alcalinos", "Metais Alcalino-Terrosos", "Metais de Transição",     "Lantanídeos", "Actinídeos", "Metais Representativos", "Semi-Metais", "Não-Metais", "Halogênios", "Gases Nobres"};
String resposta = "Gases Nobres";

        while (dica.size() == 3) {
            dica.add(aux[rand.nextInt(aux.length)]);
        }
        if (!dica.contains(resposta)) {
            dica.add(resposta);
        }

Mensagens: 1

Participantes: 1

Ler tópico completo


Viewing all articles
Browse latest Browse all 33093


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>