Java实现字符串反转

public class StrRev {

	//operator method
	public static void strPrint(String string){
		System.out.print(string);
	}
	public static void strPrint(char ch){
		System.out.print(ch);
	}
	//method 1
	public static void strRev(String str){
		for(int i = str.length() - 1;i >= 0;i --){
			strPrint(str.charAt(i));
		}
	}
	//method 2
	public static void strRev1(String str){
		StringBuffer sb = new StringBuffer(str);
		String newstr = sb.reverse().toString();
		strPrint(newstr);
	}
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		strRev("abcdd");
		strRev1("abcdd");
	}
}

你可能感兴趣的:(字符串反转)