Back

Explore Courses Blog Tutorials Interview Questions
0 votes
3 views
in Java by (10.2k points)

We create a Set as:

Set myset = new HashSet()

How do we create a List in Java?

1 Answer

0 votes
by (46k points)

To create and initialize Array in just one line in Java use:

        String[] coolStringArray = new String[]{"a" , "b" , "c"};

        System.out.println(" Array : " + Arrays.toString(coolStringArray));

    

        To create an ArrayList with three elements use:

        List<String> xStringList = new ArrayList<String>();

       xStringList.add("a");

       xStringList.add("b");

        xStringList.add("c");

To know more click here.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Dec 2, 2019 in Java by Anvi (10.2k points)

Browse Categories

...