Java List,set, the conversion between arrays, mainly using 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 loops through 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 list returned by the Arrays.aslist () method cannot be an Add object, because the implementation of the method is a arraylist of the new using the size of the array referenced by the parameter.
★collection to Array
Using the collection ToArray () method directly, the method 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 is discarded
Set set = New HashSet (arrays.aslist (array));
List,set in Java, an explanation of conversions between arrays