How to add items in list at a time?

0 votes
Hey, I was trying to initialize list at one line.

previously my code was

ArrayList<String> abc = new ArrayList<String>();
abc.add("Buenos Aires");
abc.add("La Plata");

Is there any option to add them in one line?

Aug 9, 2019 in Java by Priyanka

1 answer to this question.

0 votes

Hi Priyanka ,

I think this code snippet will help you out,

please check

import java. util.*;

public class Main


public static void main(String[] args) {

System.out.println("Hello World");

List<String> abc = Arrays.asList("Buenos Aires", "Córdoba", "La Plata");





answered Aug 9, 2019 by sampriti
• 1,100 points

Related Questions In Java

0 votes
0 answers

How to manage two JRadioButtons in java so that only one of them can be selected at a time?

How to manage two JRadioButtons in java ...READ MORE

Apr 21 in Java by kartik
• 27,570 points
+1 vote
3 answers

How to convert a List to an Array in Java?

Either: Foo[] array = list.toArray(new Foo[list.size()]); or: Foo[] array = ...READ MORE

answered Aug 7, 2018 in Java by Akrati
• 3,170 points
0 votes
1 answer

How to count the number of occurrences of an element in a List?

We can use the static frequency() method. int ...READ MORE

answered Aug 21, 2018 in Java by sharth
• 3,370 points
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 6, 2018 by Omkar 30,212 views
+11 votes
12 answers

Default parameters of XMS and XMX in JVM

You use these Java command-line parameters to ...READ MORE

answered Nov 13, 2018 in Java by Murali
0 votes
1 answer

What is $stateProvider in AngularJs?

Routing is just another way of fixing some content ...READ MORE

answered Feb 11 in Angular by Niroj
• 59,360 points
0 votes
3 answers

Does Java support Default Parameters?

You can try this with method overloading. void ...READ MORE

answered Sep 21, 2018 in Java by Sushmita
• 6,890 points
0 votes
1 answer

Is it possible to create a memory leak with Java

Here's a good way to create a memory ...READ MORE

answered May 30, 2018 in Java by Parth
• 4,630 points
0 votes
1 answer

how to compare two words in java?

hey,  I think in your code the function ...READ MORE

answered Aug 7, 2019 in Java by sampriti
• 1,100 points

edited Aug 8, 2019 by Kalgi 1,466 views
0 votes
2 answers

How do I get distinct element from list in java?

You should use a Set. it doesn't contain duplicates. If ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 57,940 points