Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - In Java, how to convert arrayList and Array, write an example.
In Java, how to convert arrayList and Array, write an example.
Refer to the original words of Java API:

Public static & ltT> list & ltT & gtasList(T ... A.

Returns a fixed-size list supported by the specified array. (Changes to the returned list are "written directly" to the array. )

Together with Collection.toArray (), this method acts as a bridge between the array-based API and the collection-based API. The returned list is serializable and RandomAccess is implemented.

Example:

Public static void main(String[] args) {

//An array is converted into a list, in which the parameters can be of any type.

List & lt string & gt list = arrays. aslist (new string [] {"ss", "SSS"});

//The list is converted into an array, and the parameter specifies the type of the array.

String[]a = list . to array(new String[0]);

//print

system . out . println(list);

For (string b: a){

system . out . print(b+ " ");

}

}