Java List,set, the conversion between arrays, mainly using the Apache Jakarta Commons collections, the specific method is as follows:
Import Org.apache.commons.collections.CollectionUtils;
String[] Strarray = {"AAA", "BBB", "CCC"};
List strlist = new ArrayList ();
Set strset = new HashSet ();
Collectionutils.addall (Strlist, Strarray);
Collectionutils.addall (Strset, Strarray);
The implementation of the Collectionutils.addall () method is simple, but it only uses the collection add () method.
If you just want to convert the array to list, you can use the Java.util.Arrays class in the JDK:
Import Java.util.Arrays;
String[] Strarray = {"AAA", "BBB", "CCC"};
List strlist = arrays.aslist (Strarray);
However, the Arrays.aslist () method returns a list that cannot add an object because the implementation of the method is a arraylist of the size of the array that uses the parameter reference.
★collection Array
Direct use of the collection ToArray () method, which has two overloaded versions:
Object[] ToArray ();
T[] ToArray (t[] a);
★map Turn Collection
Use the values () method of the map directly.
★list and set conversions
List List = new ArrayList (new HashSet ());//Fixed-size list
List List = arrays.aslist (array);//Growable
List List = new LinkedList (arrays.aslist (array))//Duplicate elements are discarded
Set set = New HashSet (arrays.aslist (array));