lundi 27 avril 2015

storing 13 random values without duplcates from a string array in java

i want distribute 13 values to a string without duplication. i have used random function and shuffle as well but it is giving me 1 value from this String array

String[] orgCards = {
                "ca", "ck", "cq", "cj", "c10", "c9", "c8", "c7", "c6", "c5", "c4", "c3", "c2",
                "sa", "sk", "sq", "sj", "s10", "s9", "s8", "s7", "s6", "s5", "s4", "s3", "s2",
                "da", "dk", "dq", "dj", "d10", "d9", "d8", "d7", "d6", "d5", "d4", "d3", "d2",
                "ha", "hk", "hq", "hj", "h10", "h9", "h8", "h7", "h6", "h5", "h4", "h3", "h2"


        };


TextView text = (TextView) findViewById(R.id.textField);
        String listString = "";
        for (String i : orgCards) {
            list.add(i);
        }
        for (int j = 1; j <= 52; j++) {
            Collections.shuffle(list);

            for (int i = 0; i < list.size(); i++) {
                orgCards[i] = list.get(i);
            }

            for (String ss : orgCards) {

                listString = ss;
            }

        }
        text.setText("my string"+" " + listString);
    }

output is :

ca




Aucun commentaire:

Enregistrer un commentaire