My problem is this: Given two strings, append them together and return the result. However, if the strings are different lengths, omit chars from the longer String
so it is the same length as the shorter String
. So "Hello" and "Hi" yield "loHi". The strings may be any length.
Is there a way to do it without using of StringBuilder
like me:
public String equalConcatenation(String a, String b) {
if(a.length() > b.length()){
StringBuilder sb = new StringBuilder(a);
sb.delete(0, (a.length() - b.length()));
return sb.toString() + b;
}
StringBuilder sb = new StringBuilder(b);
sb.delete(0, (b.length() - a.length()));
return a + sb.toString();
}