In  this tutorial, we will see “How to convert an Array to an ArrayList in Java 8?” array to arraylist java 8

Convert an Array to ArrayList in Java 8 with example...!!! Share on X

Example 1. Convert Primitive Int Array to ArrayList – Method – 1

/**
 * Convert Primitive Int Array to ArrayList - Method - 1
 * @author Deepak Verma
 */
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Convert_Primitive_Int_Array_to_ArrayList_using_Java8_Method_1 {

    public static void main(String[] args) {

    	int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    	
        List<Integer> listOfIntegers = Arrays.stream(intArray).boxed().collect(Collectors.toList());
        
        System.out.println("List: " + listOfIntegers);
 
    }
}

 

Output:

List: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

 

Example 2. Convert Primitive Int Array to ArrayList – Method – 2

/**
 * Convert Primitive Int Array to ArrayList - Method - 2
 * @author Deepak Verma
 */
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class Convert_Primitive_Int_Array_to_ArrayList_using_Java8_Method_2 {

    public static void main(String[] args) {

        int intArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
 
        List<Integer> listOfIntegers = IntStream.of(intArray).boxed().collect(Collectors.toList());
        
        System.out.println("List: " + listOfIntegers);

    }
}

 

Output:

List: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

 

Example 3. Convert Integer Array to ArrayList

/**
 * Convert Integer Array to ArrayList
 * @author Deepak Verma
 */
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class Convert_Integer_Array_to_ArrayList_using_Java8 {

    public static void main(String[] args) {

    	Integer integerArray[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    	
        List<Integer> listOfIntegers = Arrays.stream(integerArray).collect(Collectors.toList());
        
        System.out.println("List: " + listOfIntegers);
        
    }
}

 

Output:

List: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

stream to array java

Example 4. Convert String Array to ArrayListMethod – 1

/**
 * Convert String Array to ArrayList - Method - 1
 * @author Deepak Verma
 */
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Convert_String_Array_to_ArrayList_using_Java8_Method_1 {

    public static void main(String[] args) {

        String stringArray[] = {"Tom", "Bill", "Alex", "Henry", "Adam"};

        List<String> listOfStrings = Stream.of(stringArray).collect(Collectors.toList());
        
        System.out.println("List: "+listOfStrings);
    }
}

 

Output:

List: [Tom, Bill, Alex, Henry, Adam]

stream to array java

array to arraylist java 8 array to arraylist java 8 array to arraylist java 8 array to arraylist java 8

Example 5. Convert String Array to ArrayListMethod – 2

/**
 * Convert String Array to ArrayList - Method - 2
 * @author Deepak Verma
 */
import java.util.ArrayList;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class Convert_String_Array_to_ArrayList_using_Java8_Method_2 {

    public static void main(String[] args) {

        String stringArray[] = {"Tom", "Bill", "Alex", "Henry", "Adam"};

        ArrayList<String> listOfStrings = Stream.of(stringArray).collect(Collectors.toCollection(ArrayList::new));
        
        System.out.println("List: "+listOfStrings);
    }
}

 

Output:

List: [Tom, Bill, Alex, Henry, Adam]

stream to array java

array to arraylist java 8

Convert an Array to ArrayList in Java 8 with example...!!! Share on X

Do you like this Post? – then check my other helpful posts:

Other Useful References:

Author

  • Deepak Verma

    Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester.

    He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.

    View all posts