title: ArrayIndexOutOfBoundsException in Merge Sorted Arrays
body: <p>I have two arrays nums1 and nums2 with elements m and n.nums1 array has extra space greater or equal to 'm+n'....for the addition of nums2 elements.
  I have first added the elements from nums2 to nums1.Then I have sorted it.I am getting 'ArrayIndexOutOFBOundsException'.</p>
  
  <pre><code>class Solution
  {
      public void merge(int[] nums1, int m, int[] nums2, int n)
      {
          int index=nums1.length-1;
          int temp;
          for(int i=nums2.length-1;i&gt;=0;i--)
          {
              nums1[index--]=nums2[i];
          }
          for(int i=0;i&lt;nums1.length;i++)
          {
              for(int j=i+1;j&lt;nums1.length;j++)
              {
                  if(nums1[i]&gt;nums1[j])
                  {
                      temp=nums1[i];
                      nums1[i]=nums1[j];
                      nums1[j]=temp;
                  }
              }
          }
          for(int j=0;j&lt;nums1.length;j++)
          {
         System.out.print(nums2[j]+" ");
          }
      }
  }
  </code></pre>