Home > Java > javaTutorial > body text

How to convert Arrays to list in java

WBOY
Release: 2023-05-03 10:22:06
forward
1077 people have browsed it

1. Description

(1) List is only used for traversal, so use Arrays.asList().

(2) If you want to add or delete elements from List, just create a new java.util.ArrayList, and then add elements one by one.

2. Points to note

(1) This method is suitable for arrays of object type data (String, Integer...)

(2) This method The method is not recommended for use with arrays of basic data types (byte, short, int, long, float, double, boolean)

(3) This method links the array with the List list: when one of them is updated, Another automatic update

(4) does not support add(), remove(), clear() and other methods

3. The instance

will The "ArrayList" constructed by Arrays.asList() is passed into the construction method of java.util.ArrayList.

Integer[] a = new Integer[]{1, 2, 3};
List list = Arrays.asList(a);
ArrayList arrayList = new ArrayList<>(list);
Copy after login

This constructor uses the Arrays.copyOf method, so the array inside java.util.ArrayList will not have any relationship with the incoming array.

What are the basic data types of java

The basic data types of Java are divided into:

1. Integer type, used to represent the data type of integer.

2. Floating point type, a data type used to represent decimals.

3. Character type. The keyword of character type is "char".

4. Boolean type is the basic data type that represents logical values.

The above is the detailed content of How to convert Arrays to list in java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template