Java Array Permute permuteList(List inList)

Here you can find the source of permuteList(List inList)

Description

permute List

License

Open Source License

Declaration

private static List<String> permuteList(List<String> inList) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;
import java.util.Random;

public class Main {
    private static List<String> permuteList(List<String> inList) {

        //permute list
        List<String> result = new ArrayList<String>();
        Random rand = new Random(System.currentTimeMillis());

        int count = 0;
        int currIndex = inList.size() - 1;
        for (; count < inList.size(); count++) {

            int randPosition = rand.nextInt(currIndex + 1);
            String currLine = inList.get(randPosition);
            result.add(currLine);/*w ww  .  jav  a 2  s.co  m*/

            inList.set(randPosition, inList.get(currIndex));
            inList.set(currIndex, currLine);
            currIndex--;
        }
        return result;
    }
}

Related

  1. permute(String str, int startIndex, int endIndex)
  2. permute(T[] array)
  3. permute(T[] values)
  4. permuteArray(int[] array, Integer[] permutation)
  5. permuteCols(double[][] ary, int[] idx)
  6. permuteRows(double[][] ary, int[] idx)
  7. permuteVector(float[] indexVector, int rotation)