How to convert String[] to ArrayList<String>

 Posted On  | Yashwant Chavan 

In this tutorial, You will learn how to convert String[] to ArrayList.

String[] to ArrayList<String>

Refer below steps

  • Create String array with some elements.
  • Arrays.asList() method returns a fixed-size List backed by the specified array.
  • Print each element from ArrayList using for loop.

import java.util.Arrays;
import java.util.List;

class ConvertArraytoListExample {

    public static void main(String[] args) {

        String[] cities = new String[] {
        List < String > list = Arrays.asList(cities);

        for (String city: list) {
            System.out.println("List Elements:- " + city);



List Elements:- Pune
List Elements:- Mumbai
List Elements:- Delhi

© 2018

 |  Find us on Google+ |  Rss Feed

Loaded in 0.0440 seconds.