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,140 points
766 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 11, 2018 by sharth
• 3,370 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,850 points
517 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,230 points
2,905 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,640 points
910 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,920 points
17,207 views
+1 vote
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
1,173 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,920 points
1,653 views
0 votes
1 answer

Sorting an ArrayList in Java

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

answered May 5, 2018 in Java by geek.erkami
• 2,680 points
2,170 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,370 points
3,318 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,920 points
1,013 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,230 points
2,291 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP