Sort all even numbers in ascending order and then sort all odd numbers in Descending order Java Given an array of integers (both odd and even), the task is to sort
  them in such a way that the first part of the array contains odd
  numbers sorted in descending order, rest portion contains even numbers
  sorted in ascending order.
  
  Examples:


Input  : 

A[] = {1, 2, 3, 5, 4, 7, 10} 

Output : 

A[] = {7, 5, 3, 1, 2, 4, 10}



  


Input  : 

A[] = {0, 4, 5, 3, 7, 2, 1} 

Output : 

A[] = {7, 5, 3, 1, 0, 2, 4} 



  Input:
  
  The first line of input contains an integer T denoting the no
  of test cases. Then T test cases follow. Each test case contains an
  integer N denoting the size of the array. The next line contains N
  space separated values of the array.
  
  Output: 
  
  For each test case in a new line print the space separated
  values of the  new transformed array.


Constraints: 

1&lt;=T&lt;=100 

1&lt;=N&lt;=100 0

0&lt;=A[]&lt;=100



  Example: 
  
  Input: 
  
  2 
  7
  1 2 3 5 4 7 10 
  7
  0 4 5 3 7 2 1 
  
  Output: 
  
  7 5 3 1 2 4
  
  10 7 5 3 1 0 2 4


My approach:

import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;

class GFG {

    private static List&lt;Integer&gt; sortListOrder (List&lt;Integer&gt; list) {
        List&lt;Integer&gt; oddList = new ArrayList&lt;&gt;();
        List&lt;Integer&gt; evenList = new ArrayList&lt;&gt;();


        for (Integer elem : list) {
            if (elem%2 != 0) {
                oddList.add(elem);
            }
            else {
                evenList.add(elem);
            }
        }
        Collections.sort(evenList);
        Collections.sort(oddList);
        List&lt;Integer&gt; reversedList = new ArrayList&lt;&gt;();
        for (int i = oddList.size() - 1; i &gt;= 0; i--) {
            reversedList.add(oddList.get(i));
        }

        reversedList.addAll(evenList);

        return reversedList;
    }

    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        int numTests = sc.nextInt();

        while(numTests-- &gt; 0) {
            int size = sc.nextInt();
            List&lt;Integer&gt; list = new ArrayList&lt;&gt;();

            for (int i = 0; i &lt; size; i++) {
                int elem = sc.nextInt();
                list.add(elem);
            }

            List&lt;Integer&gt; sortedList = sortListOrder(list);

            for (Integer elem : sortedList) {
                System.out.print(elem + " ");
            }
            System.out.println();

        }
        sc.close();
    }
}


I have the following questions with regards to the above code:


How can I further improve my approach?
Is there a better way to solve this question?
Are there any grave code violations that I have committed?
Can space and time complexity be further improved?


Reference
You already dug into the standard library a bit (which is good) and discovered the beautiful sort method. Using this method is a perfect start.

What you overlooked is, that there is an overloaded second version of sort which accepts a comparator, so that you can perform all kinds of custom sorting with a single call.

Thus, instead of splitting the list in even and odd parts, sorting them separately, reversing one part, gluing it all back together, you could simply have created a comparator which encapsulates the logic, passed this into the sort method, and be done.

(BTW: even if you take your approach, reversing a list should be done with Collections.reverse())

So: create a comparator, do it all in a single sort call, and I look forward to see your revamped solution here in a day or so. And while you are at it: "GFG" is not an acceptable class name: what does that class do? Give it a name worth remembering!