java

How to Convert Array to ArrayList in Java

In this tutorial, we are going to see how to convert an array to arrayList in Java by using the asList() method.
 

How to Convert Array to ArrayList in Java
import java.util.*;

public class Main 
{
	public static void main(String[] args) 
	{
		//Create an array
		String[] languages = {"JAVA", "PHP", "PYTHON", "C++"};

		System.out.print("Convert an array to an ArrayList: ");
		List<String> list = new ArrayList<>();
		list = Arrays.asList(languages);
		System.out.println(list);
	}
}

Output:

Convert an array to an ArrayList: [JAVA, PHP, PYTHON, C++]
[st_adsense] mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *