title: How to pass part of an array as function argument in java?
body: <pre><code>#include&lt;stdio.h&gt;
  void fun(int a[],int n)
  {
      int i;
      for(i=0;i&lt;n;i++)       
          printf("%d ",a[i]); 
  }
  
  int main()
  {
      int arr[]={1,2,3,4,5,6};
      fun(arr+2,3);       
      return 0;
  }
  </code></pre>
  
  <p>Output: 3 4 5
  The array starting from the 3rd element has been passed here to fun() in C.
  How to do the same in JAVA, given that there are no such pointers in JAVA?</p>
  
  <p>In response to one comment below I thought to add the details of what I am actually trying to do as it is too long for the comment section. I need to access only a subsection an array recursively. Actually I am trying to find "median of two sorted arrays by comparing the medians of the two arrays" using the following algo :
  1) Calculate the medians m1 and m2 of the input arrays ar1[] 
     and ar2[] respectively.
  2) If m1 and m2 both are equal then we are done.
       return m1 (or m2)
  3) If m1 is greater than m2, then median is present in one 
     of the below two subarrays.
      a)  From first element of ar1 to m1 (ar1[0...|<em>n/2</em>|])
      b)  From m2 to last element of ar2  (ar2[|<em>n/2</em>|...n-1])
  4) If m2 is greater than m1, then median is present in one<br>
     of the below two subarrays.
     a)  From m1 to last element of ar1  (ar1[|<em>n/2</em>|...n-1])
     b)  From first element of ar2 to m2 (ar2[0...|<em>n/2</em>|])
  5) Repeat the above process until size of both the subarrays 
     becomes 2.
  6) If size of the two arrays is 2 then use below formula to get 
    the median.
      Median = (max(ar1[0], ar2[0]) + min(ar1[1], ar2[1]))/2</p>