-1

I know this is probably some really stupid question, but I couldn't find anything about it on the internet...

I have to implement an algorithm that sorts a given array. The method call looks like this:

sorter.qsort(array);

The method is static and its return type is void. Now I don't really know how to change the array without some type of notation in this form:

array = sorter.qsort(array);

The array is not type of an object, it's just initialized within the main method.

Alex238
  • 19
  • 4
  • Modifying the array within the method modifies the instance passed to the method. – Bohemian May 23 '22 at 19:02
  • It's a little unclear what you're asking. You certainly _can_ change an object solely by giving it as an argument, as you can see from e.g. [this simple example](https://ideone.com/wi1Qf2). – Louis Wasserman May 23 '22 at 19:03
  • I see, if I write something like ```arr[0] = 10``` it actually changes, but if I write ```arr = arr2``` it doesn't work. Do I really have to loop through my other array now and replace each element on its own? – Alex238 May 23 '22 at 19:33

0 Answers0