Segregate an array of 0s and 1s
With the premise that you're not allowed to use Arrays.sort It'd be more succinct to write your own sorting method.

All you really need to do is initialize an array of the size, count the 1s and set that many positions from the end to 1.

This takes advantage of the fact that integers in java are initialized to 0; the resulting solution becomes straightforward.

Try it yourself, then look at this implementation:

public class Segregate {
  public static void main(String[] args) {
    int[] a = {1, 0, 1, 0, 1, 1, 0, 1, 1, 1};
    System.out.println("Before segregation: " + join(a, ", "));
    System.out.println("After  segregation: " + join(segregate(a), ", "));
  }

  private static int[] segregate(int[] onesAndZeros) {
    int[] segregated = new int[onesAndZeros.length];
    int end = segregated.length - 1;
    for (int count = countOnes(onesAndZeros); count &gt; 0; count--) {
      segregated[end--] = 1;
    }
    return segregated;
  }

  // Obviously only works in this specific case.
  private static int countOnes(int[] onesAndZeros) {
    int count = 0;
    for (int n : onesAndZeros) {
      count += n;
    }
    return count;
  }

  private static String join(int[] nums, String delim) {
    StringBuilder joined = new StringBuilder();
    for (int num : nums) {
      joined.append(delim).append(num);
    }
    return joined.substring(delim.length());
  }
}


Output: