The code works as it is written, however; I was wondering if there are any easier or more effective ways to merge two lists.import java.util.*;public class MergeTwoSortedLists {    public static void main(String[] args)     {     java.util.Scanner input = new java.util.Scanner(System.in);     // Enter values for list1     System.out.println(Enter the amount of numbers in the first list:);     // Assign user defined length to the array     int lengthOfArray = input.nextInt();     int[] list1 = new int[lengthOfArray];     // i increments and the user values are assigned to the array until the length is exceeded       System.out.println(Enter  + list1.length +  values: );     for (int i = 0; i < list1.length; i++)      list1[i] = input.nextInt();     // Enter values for list2     System.out.println(Enter the amount of numbers in the second list:);     // Assign user defined length to the array     int lengthOfArray2 = input.nextInt();     int[] list2 = new int[lengthOfArray2];     // i increments and the user values are assigned to the array until the length is exceeded     System.out.println(Enter  + list2.length +  values: );     for (int i = 0; i < list2.length; i++)      list2[i] = input.nextInt();     // Lists one and two are merged into one list     int[] list3 = merge(list1, list2);     // Sorts the lists in numerical order     Arrays.sort(list3);     // This accesses the actual user defined integers and not their locations, printing them in an assorted array     System.out.println(The merged list is:  +Arrays.toString(list3));    }    public static int[] merge(int[] list1, int[] list2)    {        int[] list3 = new int[list1.length + list2.length];        // Both p and i increment, and list 3 is assigned the user defined integers from both list 1 and 2        for (int i = 0, p=0 ; i < list1.length || i < list2.length ; i++) {            if (i < list1.length) {                list3[p++] = list1[i];            }            if (i < list2.length) {                list3[p++] = list2[i];            }        }        return list3;    }}
Merges two lists into one list
java;array;sorting