package com.test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* 数组,List,Set之间的相互转换
* Map因为涉及到key,value 无非就是keySet,values拿出来后进行具体处理。
*
* @author tianjun tkf36897
* @version 1.0 Dec 27, 2010
*/
public class Test
{
public static void main(String[] args)
{
/*
* (1)数组 --> List
*/
Man[] temp2 = { new Man("test1"), new Man("test2"), new Man("test3") };
List<Man> tempList = Arrays.asList(temp2);
/*
* (2) List --> Set
*/
Set<Man> tempSet = new HashSet<Man>(tempList);
/*
* (3)Set --> List
*/
List<Man> tempList2 = (List<Man>)new ArrayList(tempSet);
/*
* (4)List --> 数组
*/
Man[] tempMan =(Man[])tempList.toArray();
}
}
class Man
{
private String name;
public Man(String name)
{
super();
this.name = name;
}
/**
* 获得name
* @return the name
*/
public String getName()
{
return name;
}
/**
* 设置the name
* @param name the name to set
*/
public void setName(String name)
{
this.name = name;
}
}
?