java 常用类

1、int n=Integer.parseInt("8888");      //

2、String类的常用方法

    

    String tom=new String("we are students");
    String body=new String("you are students");
    String jerry=new String("we are students");
    /**int length()*/
    System.out.println(tom.length());/*获取tom字符串的长度*/
    /**boolean equals(String s)*/
    System.out.println(tom.equals(body));   //比较当前字符串对象的实体是否与参数body指定的字符串的实体相同。正确返回true 否则返回false
    /**boolean startsWith(String s)*/
    System.out.println(tom.startsWith("we"));   //startsWith比较当前字符串对象的前缀是否是参数"we"指定的字符串.  正确返回true 否则返回false
    /**boolean regionMatches(int firstStart,String other,int otherStart,int length)*/
    System.out.println(tom.regionMatches(5,"e s",0,3));     /*从当前字符串tom位置“5”处,取长度为“3”的一个子串,并将这个子串和参数“e s”从“0”位置开始进行比较,正确返回true 否则返回false*/
    /**int compareTo(String s)*/
    if(tom.compareTo(jerry)>0){     /*tom字符串按字典序与参数(jerry)字符串比较大小,相同返回0,大于返回正值,小于返回负值。*/
            System.out.println("tom大于jerry");
    }else if(tom.compareTo(jerry)<0){
            System.out.println("tom小于jerry");
    }else if(tom.compareTo(jerry)==0){
            System.out.println("tom等于jerry");
    }
    /**boolean contains(String s)*/
    if(tom.contains("we")){     /*tom字符串中是否含有“we”字符串,含有返回true,否则返回false*/    
            System.out.println("tom字符串中含有“we”");
    }
    /**int indexOf(String s)*/
    System.out.println(tom.indexOf("e"));/*从tom字符串的头开始检索字符“e”,并返回首次发现“e”的位置*/
    System.out.println(tom.indexOf("e",3));/*从tom字符串的“3”位置开始检索字符“e”,并返回首次发现“e”的位置*/
    /**String substring(int startpoint)*/
    System.out.println(tom.substring(3));   /*获得从tom字符串的"3"位置开始截取到最后的字符串*/
    System.out.println(tom.substring(3,5));     /*获得从tom字符串的"3"位置开始截取到"5"位置(不包括5)的字符串*/   
    /**String trim()*/
    System.out.println(tom.trim());     /*获取tom字符串去掉前后空格后所剩字符串*/
    /**Integer类*/
    System.out.println(Integer.parseInt("123456"));



    






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章