字符串倒叙

字符串倒叙,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();
	}


你可能感兴趣的:(字符串倒叙)