public interface StringInverter { /** inverts a string */ String invert(String str); /** splits a string in half and inverts * the two parts */ default String invertHalf(String str) { int len = str.length(); String str1 = str.substring(0, len/2); String str2 = str.substring(len/2, len); return str2+str1; } /** removes character at index from String str * and returns the new String. */ static String removeChar(String str, int index) { if( str.length()-1 < index ) { return str; } String str1 = str.substring(0,index); String str2; if( str.length() >= index-1 ) { str2 = str.substring(index+1); } else { str2 = new String(""); } return str1+str2; } }