merge two arraylist lists in list1 while it remain sorted

后端 未结 7 889
忘了有多久
忘了有多久 2021-01-16 11:00

In my assignment the third step is to Call the method merge to merge the two lists in list1 so that the list1 remains sorted.

I write my code but it

7条回答
  •  不知归路
    2021-01-16 11:27

    Easy fix: sort afterwards.

    list1.addAll(list2);
    Collections.sort(list1);
    

    Use sets to avoid duplicates.

提交回复
热议问题