0

Hello im new to java can anyone help me with this task

Implement function that composes a new list of numbers consisting of elements of two passed lists arranged in ascending order, Implement as a function public static List cinteger > createNewList(List integer) list1, List<Integer> list2)

11th Dec 2019, 7:27 PM
KroknShar DEEB
5 odpowiedzi
+ 4
It works. Output: 2, 3, 3, 5, 7, 8, 9 Just add import java.util.List; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; above the class / at the beginning of your code.
11th Dec 2019, 8:09 PM
Denise Roßberg
Denise Roßberg - avatar
+ 1
Thanx I'll try it
11th Dec 2019, 8:18 PM
KroknShar DEEB
0
Where do you need help?
11th Dec 2019, 7:55 PM
Denise Roßberg
Denise Roßberg - avatar
0
public class Main { public static void main(String[] args) { List<Integer> list1 = new ArrayList<>(Arrays.asList(3, 9, 2, 7)); List<Integer> list2 = new ArrayList<>(Arrays.asList(8, 3, 5)); System.out.println(createNewList(list1, list2)); } public static List<Integer> createNewList(List<Integer> list1, List<Integer> list2) { List<Integer> newList = new ArrayList<>(list1.size()+list2.size()); newList.addAll(list1); newList.addAll(list2); newList.sort(Comparator.comparingInt((Integer a) -> a)); return newList; } }
11th Dec 2019, 7:56 PM
KroknShar DEEB
0
This is my code is it right?
11th Dec 2019, 7:56 PM
KroknShar DEEB