I've Created a function that accepts two String objects. The method retu a character array that contains one element for each occurrence of an alphabetic character that appears in only of the two strings. Any non-alphabetic characters in either string are ignored.
public static void main(String[] args) {
System.out.println(alphabetize("ABc","abC"));
}
static String alphabetize(String one, String two) {
String result = one + two;
String expression = "^[a-zA-Z]*$";
CharSequence inputStr = result;
Patte patte = Patte.compile(expression);
Matcher matcher = patte.matcher(inputStr);
if(matcher.matches())
{
char[] chars = result.toCharArray();
Set<Character> charSet = new LinkedHashSet<Character>();
for (char c : chars) {
charSet.add(c);
}
StringBuilder sb = new StringBuilder();
for (Character character : charSet) {
sb.append(character);
}
retu (sb.toString());
}
else
{
retu null;
}
}
First of all how can I sort the array in the way that retued value becomes in alphabetic order, with all uppercase letters appearing before any lowercase letter. Besides, case is relevant and must be taken into account. For example, if provided strings “aBA” and “abA” the function should retu an array consisting of {‘B’,’b’} because there is no uppercase B in the second string and there is no lowercase ‘b’ in the first string. Additionally, multiple occurrences are relevant and must be taken into account. For example, if provided strings “aba” and “ba”, the function should retu an array consisting of {‘a’} because the character ‘a’ appears in the second string only once.
Can anyone guide me through solving the problem? my handful of experience in java doesn't carry me to the solution.
