字符串倒叙

来源:互联网 发布:逆战刷复活币软件 编辑:程序博客网 时间:2024/05/17 11:08

字符串倒叙,eg:abc edf  返回edf abc

/** * @Description 倒叙 * @param str * @return */public String flashback(String str){if(null == str){return null;}if(str.indexOf(" ") == -1){return str;}str = doFlashback(str);String[] strArr = str.split(" ");StringBuffer result = new StringBuffer();for(String temp: strArr){if(null == temp){continue;}result.append(doFlashback(temp)).append(" ");}return result.substring(0, result.length() - 1);}/** * @Description 字符串字符翻转 * @param str * @return */public String doFlashback(String str){if(null == str){return null;}if(str.length() < 2){return str;}char[] charStr = str.toCharArray();StringBuffer result = new StringBuffer();for(int i = charStr.length - 1 ; i >= 0 ; i--){result.append(charStr[i]);}return result.toString();}


原创粉丝点击