<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)

    隨筆檔案

    文章檔案

    搜索

    •  

    最新評論

    閱讀排行榜

    評論排行榜

    主站蜘蛛池模板: 精品视频免费在线| 亚洲AV无码AV男人的天堂不卡| 免费在线观看一区| 国产免费人成视频在线观看 | 国内精品免费视频自在线| 亚洲人成网站日本片| 免费视频专区一国产盗摄| 亚洲午夜电影在线观看高清| 亚洲性线免费观看视频成熟| 亚洲人色大成年网站在线观看| 一个人看www在线高清免费看| 亚洲欧美成aⅴ人在线观看| 日本成人在线免费观看| 免费无码专区毛片高潮喷水| 国产专区一va亚洲v天堂| 国产情侣久久久久aⅴ免费 | 最近免费中文字幕大全视频 | 亚洲成AⅤ人影院在线观看| 91国内免费在线视频| 亚洲av无码成h人动漫无遮挡| 亚洲第一网站免费视频| 亚洲影院天堂中文av色| 免费观看四虎精品国产永久| caoporn成人免费公开| 久久亚洲精品成人综合| 免费H网站在线观看的| 免费精品国自产拍在线播放| 亚洲国产精品SSS在线观看AV| 免费专区丝袜脚调教视频| 亚洲国产欧洲综合997久久| 久久99亚洲综合精品首页| 久久成人无码国产免费播放| 久久夜色精品国产噜噜亚洲a| 免费大黄网站在线看| 免费无码又爽又刺激高潮视频| 亚洲看片无码在线视频| 伊人婷婷综合缴情亚洲五月| 国产精品免费观看| 一区在线免费观看| 亚洲欧洲日产v特级毛片| 亚洲 国产 图片|