Java Program to Store Even & Odd Elements of an Array into Separate Arrays Last Updated : 13 Apr, 2022 Comments Improve Suggest changes Like Article Like Report Given an array with N numbers and separate those numbers into two arrays by odd numbers or even numbers. The complete operation required O(n) time complexity in the best case. For optimizing the memory uses, the first traverse through an array and calculate the total number of even and odd numbers in it. Create two arrays with size calculated after traversing and start storing them. Below is the implementation of the above approach: Java // Java Program to Store Even & Odd // Elements of an Array into Separate Arrays public class Even_Odd { // Print array method public static void printArray(int[] array) { for (int i = 0; i < array.length; i++) System.out.print(array[i] + " "); System.out.println(); } public static void main(String[] args) { int n = 8; // array with N size int array[] = { 23, 55, 54, 9, 76, 66, 2, 91 }; int evenSize = 0; int oddSize = 0; for (int i = 0; i < n; i++) { if (array[i] % 2 == 0) evenSize++; else oddSize++; } // odd and even arrays with size int[] even = new int[evenSize]; int[] odd = new int[oddSize]; // odd and even array iterator int j = 0, k = 0; for (int i = 0; i < n; i++) { if (array[i] % 2 == 0) even[j++] = array[i]; else odd[k++] = array[i]; } // print array method System.out.print("Even Array contains: "); printArray(even); System.out.print("Odd Array contains: "); printArray(odd); } } Output: Even Array contains: 54 76 66 2 Odd Array contains: 23 55 9 91 Time Complexity: O(n) Space Complexity: O(n) Comment More infoAdvertise with us Next Article Java Program to Store Even & Odd Elements of an Array into Separate Arrays D dhatriganda07 Follow Improve Article Tags : Java Java Programs Java-Array-Programs Practice Tags : Java Similar Reads Java Program to Rearrange array elements into alternate even-odd sequence by anticlockwise rotation of digits Given an array arr[] consisting of N positive integers, the task is to rotate the digits of array elements in an anti-clockwise direction such that elements of the array elements are in alternate even-odd or odd-even form. If multiple solutions exists, then print any one of them. Otherwise, print -1 4 min read Java Program to Print the Elements of an Array Present on Even Position The task is to print all the elements that are present in even position. Consider an example, we have an array of length 6, and we need to display all the elements that are present in 2,4 and 6 positions i.e; at indices 1, 3, 5. Example: Input: [1,2,3,4,5,6] Output: 2 4 6 Input: [1,2] Output: 2 Appr 2 min read Java Program to Return the Elements at Odd Positions in a List Given a List, the task is to return the elements at Odd positions in a list. Let's consider the following list.Clearly, we can see that elements 20, 40, 60 are at Odd Positions as the index of the list is zero-based. Now we should return these elements.Approach 1:Initialize a temporary value with ze 3 min read Java Program to Print the Elements of an Array Present on Odd Position An array stores the collection of data of the same type. It is a fixed-size sequential collection of elements of the same type. In an array, if there are "N" elements, the array iteration starts from 0 and ends with "N-1". The odd positions in the array are those with even indexing and vice versa. E 3 min read Java Program to Rotate all odd numbers right and all even numbers left in an Array of 1 to N Given a permutation arrays A[] consisting of N numbers in range [1, N], the task is to left rotate all the even numbers and right rotate all the odd numbers of the permutation and print the updated permutation. Note: N is always even.Examples: Input: A = {1, 2, 3, 4, 5, 6, 7, 8} Output: {7, 4, 1, 6 2 min read Like