How do I join 2 lists

0 votes
I want to join 2 lists. What is the best way to do it in Java
May 10, 2018 in Java by Daisy
• 8,110 points
109 views

1 answer to this question.

0 votes

This is not a simpler method, but we can avoid :

List<String> listthree = new ArrayList<>(listOne.size() + listTwo.size());
listthree.addAll(listOne);
listthree.addAll(listTwo);
answered May 10, 2018 by sharth
• 3,350 points

Related Questions In Java

0 votes
1 answer

How do I join two lists in Java?

In Java 8: List<String> newList = Stream.concat(listOne.stream(), listTwo.stream()) ...READ MORE

answered Dec 30, 2020 in Java by Gitika
• 65,930 points
47 views
0 votes
2 answers

How do I get the current date and time using Java?

If you require a time stamp in ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,090 points
590 views
0 votes
1 answer

How do I fix a NullPointerException?

When you declare a reference variable (i.e. ...READ MORE

answered Apr 13, 2018 in Java by Parth
• 4,630 points
326 views
0 votes
2 answers

How do I read and convert an InputStream object to string type?

You can also use Java Standard Library ...READ MORE

answered Jul 17, 2018 in Java by Sushmita
• 6,900 points
13,123 views
0 votes
1 answer

Remove objects from an array in Java?

We can use external libraries: org.apache.commons.lang.ArrayUtils.remove(java.lang.Object[] array, int ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,290 points
322 views
0 votes
2 answers

Remove duplicate elements from an ArrayList in Java

List<String> al = new ArrayList<>(); // add elements ...READ MORE

answered Jul 26, 2018 in Java by Sushmita
• 6,900 points
634 views
0 votes
1 answer

Sorting an ArrayList in Java

You can easily do this by simply ...READ MORE

answered May 4, 2018 in Java by geek.erkami
• 2,680 points
739 views
0 votes
1 answer

Convert comma-separated String to ArrayList?

List<String> alist = Arrays.asList(str.split("\\s*,\\s*")); The above code splits ...READ MORE

answered May 17, 2018 in Java by sharth
• 3,350 points
1,514 views
0 votes
2 answers

How do I use a Priority Queue

Use the constructor overload which takes a Comparator<? ...READ MORE

answered Oct 10, 2018 in Java by Sushmita
• 6,900 points
224 views
0 votes
2 answers

How can I convert a String variable to a primitive int in Java

 Here are two ways illustrating this: Integer x ...READ MORE

answered Aug 20, 2019 in Java by Sirajul
• 59,090 points
790 views