[Java] Collections的简单运用

package test.collections;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List; public class Test01 {
public static void main(String[] args){
//Set<String> songs = new HashSet<String>();
List<String> songs = new ArrayList<String>();
Collections.addAll(songs, "冷雨夜","海阔天空","love in the rain","海洋");
//排序
Collections.sort(songs);
//随机排序
Collections.shuffle(songs);
//倒序
Collections.reverse(songs);
//交换顺序
Collections.swap(songs, 2, 3); printList(songs);
}
public static void printList(Collection<String> c){
for(String str:c){
System.out.println(str);
}
}
}
上一篇:shell脚本循环执行mysql语句


下一篇:Beta阶段第六次Scrum Meeting