Ajout aléatoire d'une String dans une balise XML à partir d'un tableau de String
en fait j'ai un tableau de string qui contient des string, je veux ajouter ses string dans une balise XML mais je veux qui m'ajoute sa aléatoirement sans répétition. voilà le code:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
String []tab=new String[listredoc.length];
for ( int j = 0 ; j < listredoc.length ; j++ ) {
Element rang = (Element) document.createElement("RangPertinence");
rang.setAttribute("Num", ""+j);
req.appendChild(rang);
Element doc1 = (Element) document.createElement("Document");
Random r = new Random();
int valeurpif = r.nextInt(listredoc.length);
tab[j]= listredoc[valeurpif];
if(tab[j] == listredoc[valeurpif])
{
valeurpif = r.nextInt(listredoc.length);
tab[j]= listredoc[valeurpif];
}
//System.out.println(""+tab[j]);
doc1.appendChild(document.createTextNode(""+tab[j]));
rang.appendChild(doc1);
} |
comment puis je faire svp?