<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 迷人笑笑 閱讀(442) 評論(0)  編輯  收藏

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


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

    常用鏈接

    留言簿(13)

    隨筆檔案

    文章檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 成人毛片免费观看视频在线| 区久久AAA片69亚洲| 国内精品免费视频自在线| 久久久久亚洲AV无码专区体验| 久久免费视频一区| 成年人性生活免费视频| 97久久国产亚洲精品超碰热| 成全视频免费高清 | 免费观看国产小粉嫩喷水| 亚洲第一成年免费网站| 少妇性饥渴无码A区免费| 成人毛片视频免费网站观看| 亚洲色大成网站www尤物| 国产伦精品一区二区三区免费迷 | 亚洲第一男人天堂| 美女无遮挡拍拍拍免费视频| 亚洲国产成人片在线观看| 鲁大师在线影院免费观看| 亚洲一区在线观看视频| 国产又黄又爽又刺激的免费网址| 黄色一级免费网站| 亚洲国产精品无码专区在线观看| 亚洲免费视频播放| 亚洲国产成人AV网站| 免费看片在线观看| 亚洲欧洲无码一区二区三区| 亚洲第一区精品日韩在线播放| 亚洲免费综合色在线视频| 亚洲熟女乱综合一区二区| 色五月五月丁香亚洲综合网| 亚洲中文字幕在线观看| 18禁无遮挡无码国产免费网站| 亚洲乱码av中文一区二区| 国产亚洲精品国看不卡| 亚洲精品免费在线视频| 香港经典a毛片免费观看看| 亚洲日韩区在线电影| 中文无码成人免费视频在线观看| 亚洲激情电影在线| 亚洲精品一级无码鲁丝片| 96免费精品视频在线观看|