[Java] List type / Array type conversion

Convert List type to Array type

python


Foo[] array = list.toArray(new Foo[list.size()]);

Or

Foo[] array = new Foo[list.size()];
list.toArray(array);

Convert Array type to List type

String[] stringArray = {"aaa", "bbb", "ccc"};
List<String> stringList = Arrays.asList(stringArray); 

However, elements cannot be added or deleted using the above writing method. (Reference URL) When adding / deleting elements, describe as follows.

String[] stringArray = {"aaa", "bbb", "ccc"};
List<String> stringList = new ArrayList<>(Arrays.asList(stringArray));

Recommended Posts

[Java] List type / Array type conversion
Java type conversion
[Java] Conversion from array to List
Java array / list / stream mutual conversion list
About Java Array List
[Java] Date type conversion
[Java] Precautions for type conversion
[Java] Type conversion speed comparison
Java Primer Series (Type Conversion)
[Java] array
Java array
Java array
java (array)
Java array
[Java] Array
Java array
java array
[Java] Array
Java8 list conversion with Stream map
java array variable
Java date data type conversion (Date, Calendar, String)
[Easy-to-understand explanation! ] Reference type type conversion in Java
[JAVA] Stream type
[Java ~ Variable definition, type conversion ~] Study memo
[Java] Enumeration type
Java memorandum (list)
Java Optional type
Clone Java List.
Java study # 3 (type conversion and instruction execution)
[Java] Array notes
Array / list / map
Java double type
[Basic knowledge of Java] About type conversion
Immutable (immutable) List object conversion function in Java8
Java-automatic type conversion
Java 8 LocalDateTime type conversion stuff (String, java.util.Date)
[Java] Calculation mechanism, operators and type conversion
Type conversion from java BigDecimal type to String type
About List [Java]
[Java] From two Lists to one array list
[Introduction to Java] About type conversion (cast, promotion)
Java type conversion (String, int, Date, Calendar, etc.)
[java] sort in list
[Java] Full-width ⇔ half-width conversion
[Java] Data type ①-Basic type
Uri → String, String → Uri type conversion
[Java, Kotlin] Type Variance
Java class type field
Type determination in Java
Java study # 1 (typical type)
[Java ~ Array ~] Study memo 4
[Java] About enum type
[Memo] Java Linked List
Endian conversion with JAVA
java: How to write a generic type list [Note]
Java learning memo (data type)
[Java] ArrayList → Should I specify the size in array conversion?
Try functional type in Java! ①
[Java Bronze] Learning memo (interface, static method, type conversion, etc.)
Java study # 7 (branch syntax type)
[Java] List OS-dependent standard libraries