One, the set conversion to an array:
Using the collection. ToArray () method, depending on the type of the conversion array can be divided into:
1. Convert to object[] Type array
For example: object[] Listarray = List.toarray ();
object[] SetArray = Set.toarray ();
2. Translate to a specific type array
For example: string[] ListArray1 = (string[]) List.toarray (newstring[0])
or string[] ListArray2 = (string[]) List.toarray (Newstring[list.size ()));
String[] SetArray1 = (string[]) Set.toarray (newstring[0]);
or String SetArray2 = (string[]) Set.toarray (Newstring[set.size ()));
Second, the array is converted into a set:
Use the array. Aslist () method
List List = new ArrayList ();
List = arrays.aslist (array); Note: for int[] Arrays You cannot do this directly, because the parameters of the Aslist () method must be an object. Int[] should first be converted to integer[].
Set set = New HashSet (array.aslist (Array)); Use list to construct set
The collection of Java basics and the conversion of arrays to each other