I want to randomize or shuffle the order of the string array using the code below
public static void main(String[] args) {
        String str[]= {"Vxds", "Cvda", "Xcgi", "Atdr", "Mbeds", "0bda"};
        String strTmp[]=str;
        
        ArrayList<Integer> list = new ArrayList<Integer>();
        for (int i=0; i<str.length; i++) {
            list.add(new Integer(i));
        }
        
        Collections.shuffle(list);
        
        for (int i=0; i<str.length; i++) {
            strTmp[i]=str[list.get(i)];
            System.out.println(strTmp[i]);
        }
    }
The reason I do it like this instead of print it out directly is because I want to make it into a function later on. That's why I passed it to strTmp[] as that is what I want the function to return. But, the code just didn't function as I expected. It prints out several same value. How can I do it the right way? Thanks for the answer...




Integer(int)constructor is deprecated. You should always usevalueOf(int).String[] strinstead ofString str[].