How to perform merge sort in Java?

public class MyMergeSort
{
void merge(int arr[], int beg, int mid, int end)
{

int l = mid - beg + 1;
int r = end - mid;

intLeftArray[] = new int [l];
intRightArray[] = new int [r];

for (int i=0; i<l; ++i)
LeftArray[i] = arr[beg + i];

for (int j=0; j<r; ++j)
RightArray[j] = arr[mid + 1+ j];

int i = 0, j = 0;
int k = beg;
while (i<l&&j<r)
{
if (LeftArray[i] <= RightArray[j])
{
arr[k] = LeftArray[i];
i++;
}
else
{
arr[k] = RightArray[j];
j++;
}
k++;
}
while (i<l)
{
arr[k] = LeftArray[i];
i++;
k++;
}

while (j<r)
{
arr[k] = RightArray[j];
j++;
k++;
}
}

void sort(int arr[], int beg, int end)
{
if (beg<end)
{
int mid = (beg+end)/2;
sort(arr, beg, mid);
sort(arr , mid+1, end);
merge(arr, beg, mid, end);
}
}
public static void main(String args[])
{
intarr[] = {90,23,101,45,65,23,67,89,34,23};
MyMergeSort ob = new MyMergeSort();
ob.sort(arr, 0, arr.length-1);

System.out.println("\nSorted array");
for(int i =0; i<arr.length;i++)
{
System.out.println(arr[i]+"");
}
}
}

Output:

Sorted array
23
23
23
34
45
65
67
89
90
101
Author's Other questions
 Write a program to calculate the difference between the sum of the odd level and even level nodes of a Binary Tree Write a program in Java to find the maximum and minimum value node from a circular linked list. Write a program in Java to create a doubly linked list containing n nodes How to perform quicksort in Java? How to perform Linear Search in Java? How to perform Selection Sort in Java? How to perform Binary Search in Java? How to perform Bubble Sort in Java? Can RMI and CORBA based applications interact? What is JRMP? What is the use of HTTP-tunneling in RMI? What are the steps involved to write RMI based programs? What is the purpose of stub and skeleton? What do you understand by the bean persistent property? What is the purpose of using the Java bean? What is a JavaBean? How will you load a specific locale? What is Locale? Can you write a Java class that could be used both as an applet as well as an application? What is an applet?