public String extraFront(String str) { if (str.length() < 2) { return str + str + str; } else { String front = str.substring(0,2); return front + front + front; } } public String extraFront2(String str) { int indexStop = Math.min(2,str.length()); String front = str.substring(0,indexStop); return front + front + front; }