米字键

博客园 首页 新随笔 联系 订阅 管理

 

public class Homework {

    public static void main(String[] args) throws ParseException {
    
      
            lower();    全部调用


            upper();


            repalce();


            repalce1();


            trim();

 

 

      public static void  trim(){

 

 

//  String trim(): 去掉字符串两端空格


                String s="   hello    ";  //定义字符串两端加空格


                System.out.println(s);  //打印一次


                String s1=s.trim();  //去掉两端空格


                System.out.println(s1);  //打印取掉以后的值
    }

 

 

 

//    String repalce(String old, String newstr): 将字符串中的老字符串,替换为新字符串


            public static void repalce1(){


               String s="old";  //定义字符串


                String s1=s.replace("old","newstr");    //把old 替换成 newStr


                System.out.println(s1);    //打印
    }

 

 

 

 

 

//    String repalce(char oldChar, char newChar): 将字符串中的老字符,替换为新字符

 


          private static void repalce() {

  
            String s="oldChar";    //定义字符串
        
              String s1=s.replace("old","new" );  //把old转化成new后面不变


              System.out.println(s1);
    }

 

 



          private static void upper() {

 

//    String toUpperCase(): 字符串转成大写

 


          String s="hello";  // 定义字符串


          String s1=s.toUpperCase();  //把字符串转换成大写


          System.out.println(s1);  //打印
    }

 

 

 


      private static void lower() {
   //      String toLowerCase(): 字符串转成小写


            String S="HELLO";  //定义大写字符串


            String s1=S.toLowerCase();    //把字符串转化成小写


            System.out.println(s1);      //打印
        
    }

  
  
    }

posted on 2019-03-19 22:02  米字键  阅读(557)  评论(0编辑  收藏  举报