MergeArrays

Run Settings
LanguageJava
Language Version
Run Command
import java.util.*; class Main { public List<Integer> mergeList(List<Integer> firstList, List<Integer> secondList){ List<Integer> mergedList = new ArrayList<Integer>(); if (firstList== null || secondList == null){ System.out.println("The lists cannot be null"); } if (firstList.isEmpty() || secondList.isEmpty()){ System.out.println("The lists cannot be empty."); } int firstIndex =0; int secondIndex= 0; while (firstIndex < firstList.size() && secondIndex < secondList.size()){ System.out.println("1"); if (firstList.get(firstIndex) < secondList.get(secondIndex)){ System.out.println("2"); mergedList.add(firstList.get(firstIndex++)); } if (firstList.get(firstIndex) > secondList.get(secondIndex)){ System.out.println("3"); mergedList.add(secondList.get(secondIndex++)); } System.out.println("Still here"); } /* while (firstIndex < firstList.size()){ mergedList.add(firstList.get(firstIndex++)); } while (secondIndex < secondList.get(secondIndex)){ mergedList.add(secondList.get(secondIndex++)); }*/ return mergedList; } public static void main(String[] args) { System.out.println("Hello World!"); List<Integer> firstList= new ArrayList<Integer>(); List<Integer> secondList= new ArrayList<Integer>(); firstList.add(0); firstList.add(3); firstList.add(4); firstList.add(31); secondList.add(4); secondList.add(6); secondList.add(30); Main main = new Main(); System.out.println("start"); List<Integer> mergedList = main.mergeList(firstList, secondList); /*for (int element : mergedList){ System.out.println(""+element); }*/ } }
Editor Settings
Theme
Key bindings
Full width
Lines