I have a problem with Java and it is as follows:
I have these two String
:
String string1 = "aabcdef";
String string2 = "abcghi";
And I need to get this "adefghi" .
public static String regenerate(String a, String b)
{
String common = null;
common = a.replaceAll("[" + b + "]", "");
common += b.replaceAll("[" + a + "]", "");
return common;
}
Where what I want to do is:
a abc def
abc ghi
Leaving only: a def ghi
My problem is that this prints "defghi" , which is a wrong result, can someone help me?