Java Program to Move All Uppercase Characters to the End
Given a string that contains uppercase letters as well as lower case letters. The task is to move all uppercase characters at the end of the String. The uppercase characters must be in the same order as in the original string.
Input : "heLLGFg" Output : "hegLLGF" Input : "Hello" Output : "elloH"
Here we are having two different approaches to get to the problem namely as follows:
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.
- Using ASCII values of the characters.
- Using queue data structures
Approach 1: Using ASCII values of the characters.
- Iterate the character of the string one by one and checks the ASCII values of the respective character of the string.
- For all uppercase letters, ASCII values lie under [65-90] char values. Store the characters of these ASCII values in the String variable and print the string at the end of Iteration.
Approach 2: Using queue data structures
- Queue Data structure implements First in First out concept, We use this concept and store the uppercase characters in the queue.
- Print all the characters except the uppercase characters.
- After the iteration removes all the elements from the queue.