If I have an array of characters filled with characters, and I have a String
initialized with some initial value, then how can I make sure that the characters in the array are sorted in the order of occurents of how they appear within the string.
You can make the following additional assumptions:
- unused characters should appear at the end in their original order.
- if multiple occurrences of the same character occur within the array, they can refer to the same occurrence within the string.
Example, assume following two initialized variables:
char [] arr= new char[5] { 'a', 'd', 'v', 'd', 'j' };
String str = "dad";
Then the expected result would be that the variable arr
would have sorted the characters as follows:
{ 'd', 'a', 'd', 'v', 'j' }