Java ArrayList how to add elements at the beginning

后端 未结 14 1578
忘了有多久
忘了有多久 2020-12-02 06:49

I need to add elements to an ArrayList queue whatever, but when I call the function to add an element, I want it to add the element at the beginning of the arra

14条回答
  •  半阙折子戏
    2020-12-02 07:33

    Take this example :-

    List element1 = new ArrayList<>();
    element1.add("two");
    element1.add("three");
    List element2 = new ArrayList<>();
    element2.add("one");
    element2.addAll(element1);
    

提交回复
热议问题