import java.util.*;
public class Test {
private String[] listToArray(List<String> list) {
return list.toArray(new String[list.size()]);
}
private List<String> arrayToList(String[] array) {
return Arrays.asList(array);
}
private Set<String> listToSet(List<String> list) {
return new HashSet<String>(list);
}
private List<String> setToList(Set<String> set) {
return new ArrayList<String>(set);
}
private Set<String> mapToSet(Map<String, String> map) {
return new HashSet<String>(map.values());
}
private Map<String, String> setToMap(Set<String> set) {
Map<String, String> map = new HashMap<String, String>();
map.put(set.iterator().next(), set.iterator().next());
return map;
}
private List<String> mapToList(Map<String, String> map) {
return new ArrayList<String>(map.values());
}
private Map<String, String> listToMap(List<String> list) {
Map<String, String> map = new HashMap<String, String>();
map.put(list.iterator().next(), list.iterator().next());
return map;
}
}
2019/04/26
Java 1.6 Array to list / List to Set / Set to Map
程式碼: