数组转集合
使用 Java Util 类的 Arrays.asList(name) 方法将数组转换为集合:
public class ArrayToCollection{
public static void main(String args[])
throws IOException{
int n = 5; // 5 个元素
String[] name = new String[n];
for(int i = 0; i < n; i++){
name[i] = String.valueOf(i);
}
List list = Arrays.asList(name);
System.out.println();
for(String li: list){
String str = li;
System.out.print(str + " ");
}
}
}
集合比较
将字符串转换为集合并使用 Collection 类的 Collection.min() 和 Collection.max() 来比较集合中的元素:
class Main {
public static void main(String[] args) {
String[] coins = { "Penny", "nickel", "dime", "Quarter", "dollar" };
Set set = new TreeSet();
for (int i = 0; i < coins.length; i++ 


