Java, array return : <p>I'm new at Java. I'm studying through Programming Hub app. When i read HeapSort code i find out that method fnSortHeap not return array but main method still can print out it. From informations that i found in main method must be smt like that: </p>

<blockquote>
  <p>int arr2[]; </p>
  
  <p>arr2 = fnSortHeap(arr, i - 1);</p>
</blockquote>

<p>and in fnSortHeap method must </p>

<blockquote>
  <p>return array;</p>
</blockquote>

<pre><code>class HeapSort
{
    public static void main(String a[])
    {
        int i;
        int arr[] = {1, 3, 4, 5, 2};

        System.out.println("\nUnsorted Array\n---------------");

        for (i = 0; i &lt; arr.length; i++)
        {
            System.out.print(" " + arr[i]);
        }

        for (i = arr.length; i &gt; 1; i--)
        {
            fnSortHeap(arr, i - 1);
        }

        System.out.println("\n\nSorted array\n---------------");

        for (i = 0; i &lt; arr.length; i++)
        {
            System.out.print(" " + arr[i]);
        }
    }

    public static void fnSortHeap(int array[], int arr_ubound)
    {
        int i, o;
        int lChild, rChild, mChild, root, temp;

        root = (arr_ubound - 1) / 2;

        for (o = root; o &gt;= 0; o--)
        {
            for (i = root; i &gt;= 0; i--)
            {
                lChild = (2 * i) + 1;
                rChild = (2 * i) + 2;

                if ((lChild &lt;= arr_ubound) &amp;&amp; (rChild &lt;= arr_ubound))
                {
                    if (array[rChild] &gt;= array[lChild])
                        mChild = rChild;
                    else
                        mChild = lChild;
                }
                else
                {
                    if (rChild &gt; arr_ubound)
                        mChild = lChild;
                    else
                        mChild = rChild;
                }

                if (array[i] &lt; array[mChild])
                {
                    temp = array[i];
                    array[i] = array[mChild];
                    array[mChild] = temp;
                }
            }
        }

        temp = array[0];
        array[0] = array[arr_ubound];
        array[arr_ubound] = temp;
        return;
    }
}
</code></pre>
