java String七种方法的使用isEmpty() charAt() toLowercase() toUpperCase() replace() trim() 的使用

/**
	 *  判断字符串非空
	 */
	
	public  static boolean fun1(String str){
		 
		return str.isEmpty() ? true :false;
	}
	
	/**
	 * 返回索引上的字符
	 */
	public  static char getStr(String str,int index){
		return str.charAt(index);
	}
	/**
	 * 字符串转换成小写
	 */
	
	public static String to_lower(String str){
		return str.toLowerCase();
		
	}
	/**
	 * 字符串转换成大写
	 */
	public static String to_upper(String str){
		return str.toUpperCase();
	}
	/**
	 * 将字符串的老字符串转换成新字符串
	 */
	
	public static void oldToNew(){
		String str="lideng";
		String str2=str.replace('l', 'L');
		System.out.println(str2);
		
	}
	
	/**
	 * 将字符串中的老字符串,替换为新字符串
	 */
	public static void oldTo_new(){
		
		String str1="gghhccxx";
		String str2=str1.replace("gg", "GG");
		System.out.println(str2);
	}
	
	/**
	 * 去掉两端空格
	 */
	public static String delTrim(String str){
		return str.trim();
	}

  

猜你喜欢

转载自www.cnblogs.com/qurui1997/p/10560617.html