数组乱序排列

记录一下将顺序数组进行乱序排序的代码

 

List<Object> list = new ArrayList<Object>();

//list初始化,省略

int size = list.size();

for(int i=0;i<size;i++){

  Object obj1 = list.get(i);

  int index = RandomUtils.nextInt(size);

  Object obj2 = list.get(index);

  list.set(i,obj2);

  list.set(index,obj1);

}

 

posted @ 2015-03-19 10:42  TomSnail  阅读(576)  评论(2编辑  收藏  举报