Java Program For Case Specific Sorting
Given a string S consisting of uppercase and lowercase characters. The task is to sort uppercase and lowercase letters separately such that if the “i”th place in the original string had an Uppercase character then it should not have a lowercase character after being sorted and vice versa. it is described in the illustration as shown below:
Input : srbDKi
Processing : After sorting we have to place the lowercase characters to the lowercase and uppercase character to specific uppercase character
- We will use two ArrayList one to store the lowercase values and the second to store uppercase values.
- After adding elements into the lists we will sort the list using Collections.sort(list) method
- After sorting, we will traverse the string and check case-specific and store the element at the correct position
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.