Java String Cutting Solution