<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 14,  comments - 7,  trackbacks - 0
             java API 是應用編程接口,是一種規范,指明編寫應用程序的程序員如何訪問類和行為和狀態。
             下面就列舉個API 中string類中的10個方法的小應用:
            1.  contains:當且僅當此字符串包含指定的char值序列時,返回true
             
    public class Contains {
            
    public static void main(String[] args) {
            String str 
    ="abcdefg";
            
    boolean i = str.contains("ab");
            System.out.print(i);
            
        }


    }
          如果把上面程序中的 boolean i = str.contains("ab")改為 boolean i = str.contains(null) 即把指定的char值序列改為空值,便會出現NullPointExcption的異常。
         
          2.copyValueOf:通過這個方法把給定數組中的相應的部分copy到字符串中輸出來
    public static void main(String[] args) {
            
    char[] x = {'a','b','c','d','e'};
            String str 
    = null;
            str 
    = String.copyValueOf(x,2,3);
            System.out.print(str);

        }


    }
            str = String.copyValueOf(x,2,3)其中的x表示原數組,2表示偏移量,3表示要輸出的長度。
     
           3.Intern:返回字符串對象的規范化表示形式,遵循以下規則:對于任意兩個字符串s,t,當且僅當s.equals(t) 為true時,s.intern() == t.intern 才為true
    public static void main(String[] args) {
        String str1 
    = "HelloWorld";
        String str2 
    = "Hello"+"World";
        System.out.println(str1 
    == str2);
        System.out.print(str1.intern( ) 
    == str2.intern());
        }


    }
         4.length:返回此對象的長度
    public class Length {

        
        
    public static void main(String[] args) {
            String str 
    = "abcdefg";
            System.out.print(str.length());
        }


    }
          5.matches告知此字符串是否匹配指定的正則表達式,當且僅當匹配給定的正則表達式時,輸出true
    public class Matches {

        
        
    public static void main(String[] args) {
            String str 
    = "abcdefg";
            
    boolean i =str.matches( "abcdefg");
            System.out.println(i);
        }


    }
          6.replaceFirst:用給定的字符串替換正則表達式匹配的字符串
    public class ReplaceFirst {
            
    public static void main(String[] args) {
            String str 
    = "abcdefgh";
            String str1 
    = str.replaceFirst("ef""k");
            System.out.print(str1);
        }


    }

         7.subString:返回一個新字符串,他是此字符串的一個字子符串,該子字符串從指定字符串索引處的字符開始,直到指定的索引結束的字符結束
    public class Substring {

        
        
    public static void main(String[] args) {
            String str 
    = "abcdefgh";
            String str1 
    = str.substring(24);
            System.out.print(str1);
        }

    }

    其中String str = "str.substring(2,4)"中2表示起始索引(包括),4表示結束索引(不包括)
    如果把其實索引改為負數或結束索引大于字符串長度,便會出現indexoutBounsException的異常
           8.toCharArray:將此字符串轉化為一個新的字符數組
    public class ToCharArray {
        
    public static void main(String[] args) {
            String str1 
    = "一定要死幸福";
            
    char[] str2 = str1.toCharArray( );
            
    for(int i=0;i<str2.length;i++){
            System.out.println(str2[i]);
            }

        }

    }
          9.trim:此方法可用于截去開頭和尾部的空白
    public class Trim {
        
    public static void main(String[] args) {
        String str 
    = "  abcd   ";
        String strArr 
    = str.trim();
        System.out.println(strArr);
        }


    }
         10.valueOf:返回char參數的字符串表示形式
         
    public class ValueOf {
        
    public static void main(String[] args) {
        
    char[] x = {'a','b','c','d'};
        String str1 
    ="null";
        str1 
    = String.valueOf(x);
        System.out.print(str1);

        }


    }

    posted on 2010-10-09 17:48 迷人笑笑 閱讀(443) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    <2010年10月>
    262728293012
    3456789
    10111213141516
    17181920212223
    24252627282930
    31123456

    常用鏈接

    留言簿(13)

    隨筆檔案

    文章檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 一个人免费高清在线观看| 国产高清在线免费| 性短视频在线观看免费不卡流畅| 国产精品成人免费视频网站京东| 亚洲国产成人精品女人久久久 | 亚洲一二成人精品区| 亚洲人成在线影院| 999久久久免费精品播放| 免费国产成人午夜私人影视| 亚洲国产国产综合一区首页| 久久国产免费观看精品| 日韩精品电影一区亚洲| 亚洲制服丝袜一区二区三区| 国产精品玖玖美女张开腿让男人桶爽免费看| 美女视频黄a视频全免费| 亚洲一级黄色大片| 久久国产精品2020免费m3u8| 亚洲精品乱码久久久久久蜜桃| 亚洲一区动漫卡通在线播放| 成人无码区免费视频观看| 亚洲人成人无码.www石榴| 国产91免费视频| 亚洲午夜久久影院| 成人免费的性色视频| 亚洲欧洲国产日韩精品| 无码国产精品一区二区免费式影视| 亚洲日韩国产精品乱-久| 4399影视免费观看高清直播| 亚洲AV无码成人精品区蜜桃| 二个人看的www免费视频| 亚洲成片观看四虎永久| 中文字幕在线成人免费看| 亚洲色欲www综合网| 6080午夜一级毛片免费看| 亚洲妇女熟BBW| 亚洲AV无码一区二区三区国产| 七色永久性tv网站免费看| 亚洲综合无码一区二区痴汉 | 免费无码黄十八禁网站在线观看| 亚洲国产成人AV网站| 免费无码又爽又刺激高潮|