Sort Array By Parity || Two Pointer || Java || CF
ApproachWe’ll use an extra pointer (j) to keep track of the position where the next even number should be placedInitialize j pointer :Pointer j will track the p

# Approach

**We’ll use an extra pointer (j) to keep track of the position where the next even number should be placed**

## Initialize j pointer :

Pointer j will track the position in the array where the next even number should go. It starts at index 0

 **Purpose of the j pointer:**

- The j pointer marks the position where the next even number should be placed. As we traverse the array, we want to move even numbers to the front, and j helps us keep track of the first available position for the next even number

## Iterate through the array:

For each number in the array, check if the number is even

If the number is even, swap it with the number at index j (this ensures that even numbers are moved towards the front)

After the swap, increment j to point to the next position

## Termination:

Continue iterating until all numbers have been processed.





# Code
```java []
class Solution {
    public int[] sortArrayByParity(int[] nums) {
        int j=0;
        for(int i=0;i<nums.length;i++){
            if(nums[i]%2==0){
                int temp=nums[i];
                nums[i]=nums[j];
                nums[j]=temp;
                j++;
            }
            
        }
        return nums;
    }
}
```
['Java']