Convert an Array of Strings to a List

Convert an Array of Strings to a List

The java.util.Arrays class has an asList method to convert the argument array into a list. This will be handy when there are large amounts of information that you need to enumerate.

import java.util.Arrays;import java.util.List;public class ConvertArrayToList{    public static void main(String args[])   {      ConvertArrayToList convertArrayToList = new ConvertArrayToList();      convertArrayToList.proceed();   }      private void proceed()   {      //String array containing the week days      String daysOfWeek[] =  {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};      List listOfWeekDays =  Arrays.asList(daysOfWeek); //method to convert into a list      System.out.println("Week days: "+listOfWeekDays);   }}/*

Expected output:

[root@mypc]# java ConvertArrayToListWeek days: [Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday]*/
See also  Java Developer Jobs: Your Guide to Landing the Perfect Position in 2024

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist