Программа для объединения двух списков в один

Я должен объединить эти два списка. Это моя незавершенная программа кодирования. Я не могу двигаться дальше. Мне нужно помочь закончить это задание. Объединенный список должен содержать все указанные номера. Также, если хотите, можете ли вы оставить процесс решения деталей для моего изучения?

public class Lab18bvst
{
    public static void main(String[] args)
    {
        int[] jsaList1 = {101, 105, 115, 125, 145, 165, 175, 185, 195, 225, 235, 275, 305, 315, 325, 335, 345, 355, 375, 385};
        int[] jsaList2 = {110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 270, 280, 320, 350, 400};

        Array list1 = new Array(jsaList1,"List #1");
        Array list2 = new Array(jsaList2,"List #2");
        Array list3 = new Array("Merged List");

        list3.merge(list1,list2);

        list1.display();
        list2.display();
        list3.display();

    }

}
class Array
{
    private ArrayList<Integer> list;
    private int size;
    private String listName;

    public Array(String ln)
    {
        list = new ArrayList<Integer>();
        size = 0;
        listName = ln;
    }

    public Array(int[] jsArray, String ln)
    {
        list = new ArrayList<Integer>();
        size = jsArray.length;
        listName = ln;
        for (int j = 0; j < size; j++)
            list.add( new Integer( jsArray[j] ));
    }

    public void display()
    {
        System.out.println("\n" + listName + ":\n");
        System.out.println(list + "\n");
    }

    public void merge(Array that, Array theOther)
   {
      int thatIndex, theOtherIndex;
      thatIndex = theOtherIndex = 0;

      for (int j = 1; j <= that.size + theOther.size; j++)
      {
         if (thatIndex >= that.size)
         {
            while(theOtherIndex < theOther.size)
            {
               this.list.add(theOther.list.get(theOtherIndex));
               theOtherIndex++;
            }
         }
         else if (theOtherIndex >= theOther.size)
         {
            while(thatIndex < that.size)
            {
               this.list.add(theOther.list.get(thatIndex));
               thatIndex++;
            }
         }
         else if

         else

      }

   }
}

person Jeehyun Yoon    schedule 02.04.2018    source источник
comment
Мне нужен 1 миллион долларов как можно скорее !!! 1!   -  person Johannes Kuhn    schedule 02.04.2018
comment
@JohannesKuhn: Мне нужен пони как можно скорее !!   -  person halfer    schedule 02.04.2018
comment
Прочтите При каких обстоятельствах я могу добавить к своему вопросу «срочно» или другие похожие фразы, чтобы получить более быстрые ответы? - Резюмируя, можно сказать, что это не идеальный способ обращения к волонтерам и, вероятно, контрпродуктивен для получения ответов. Пожалуйста, воздержитесь от добавления этого к своим вопросам.   -  person halfer    schedule 02.04.2018
comment
@halfer ПОНИ !!! Важнее 1 миллиона долларов. Я люблю это.   -  person Johannes Kuhn    schedule 03.04.2018


Ответы (1)


Самый простой способ объединить 2 списка

List<String> newList = new ArrayList<String>();
newList.addAll(listOne);
newList.addAll(listTwo);
person Parth Mody    schedule 02.04.2018
comment
это конкатенация, а не совсем слияние (дубликаты не удаляются). - person guillaume girod-vitouchkina; 02.04.2018
comment
@ guillaumegirod-vitouchkina Сделайте newList тип Set, и он будет. - person Strikegently; 02.04.2018