0 votes
1 view
in Java by (3.5k points)

How do I declare an ArrayList with values?

I've tried the following but it returns a syntax error:

import java.io.IOException;

import java.util.ArrayList;

public class test {

    public static void main(String[] args) throws IOException {

        ArrayList<String> x = new ArrayList<String>();

        x = ['xyz', 'abc'];

    }

}

1 Answer

0 votes
by (42.1k points)

Use this one:

ArrayList<String> x = new ArrayList(Arrays.asList("abc", "mno"));

Related questions

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...