Randomizar um ArrayList

3 respostas
anderson.bonavides

Pessoal gostaria de saber como faço pra ranomizar um ArrayList.

Alguem já fez isto?

Grato!

3 Respostas

I

Velho eu fiz uma Source que acho que vai te ajudar, segue abaixo:

public class PhraseOMatic {
	public static void main(String args[]){

	String[] wordListOne = {"24/7","Várias camadas","30.000 pés","B-to-B","todos ganham","front end","baseado na web","difundido","inteligente","seis sigma","caminho crítico","dinâmico"};
	
	String[] wordListTwo = {"habilitado","adesivo","valor agregado","orientado","central","distribuído","agrupado","solidificado","independente da maquina","posicionado","em rede","dedicado","avançado","alinhado","destinado","compartilhado","cooperativo","acelerado"};
	
	String[] wordListThree = {"processo","ponto maximo","solução ","arquitetura","habilitação do núcleo","estratégia","mindshare","portal","espaço","visão","paradigma","missaõ"};
	
	int oneLength = wordListOne.length;
	int twoLength = wordListTwo.length;
	int threeLength = wordListThree.length;
	
	int rand1 = (int) (Math.random() * oneLength);
	int rand2 = (int) (Math.random() * twoLength);
	int rand3 = (int) (Math.random() * threeLength);
		
	String phrase = wordListOne[rand1] + " " + wordListTwo[rand2] + " " + wordListThree[rand3];
	
	System.out.println("Precisamos de "+ phrase);
	
}



}
anderson.bonavides

itlsml

Obrigado pela ajuda.

=)

Mauricio_Linhares

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Collections.html#shuffle(java.util.List)

Criado 25 de outubro de 2008
Ultima resposta 25 de out. de 2008
Respostas 3
Participantes 3