国产睡熟迷奷白丝护士系列精品,中文色字幕网站,免费h网站在线观看的,亚洲开心激情在线

      <sup id="hb9fh"></sup>
          1. 千鋒教育-做有情懷、有良心、有品質(zhì)的職業(yè)教育機構(gòu)

            手機站
            千鋒教育

            千鋒學習站 | 隨時隨地免費學

            千鋒教育

            掃一掃進入千鋒手機站

            領取全套視頻
            千鋒教育

            關注千鋒學習站小程序
            隨時隨地免費學習課程

            當前位置:首頁  >  技術(shù)干貨  > Java-String的常用方法總結(jié)

            Java-String的常用方法總結(jié)

            來源:千鋒教育
            發(fā)布人:小鋒
            時間: 2019-08-29 14:45:00 1567061100

              一、String類

              String類在java.lang包中,java使用String類創(chuàng)建一個字符串變量,字符串變量屬于對象。java把String類聲明的final類,不能繼承。String類對象創(chuàng)建后不能修改,由0或多個字符組成,包含在一對雙引號之間。

              二、String類構(gòu)造方法

              1、public String()

              無參構(gòu)造方法,用來創(chuàng)建空字符串的String對象。

              String str1 = new String();

              String str2 = new String("asdf");

              2、public String(String value)

              String str2 = new String("asdf");

              3、public String(char[] value)

              char[] value = {'a','b','c','d'};

              String str4 = new String(value);

              4、public String(char chars[], int startIndex, int numChars)

              char[] value = {'a','b','c','d'};

              String str5 = new String(value, 1, 2);

              5、public String(byte[] values)

              byte[] strb = new byte[]{65,66};

              String str6 = new String(strb);

              三、String類常用方法

              1、public char charAt(int index)

              參數(shù)

              index -- 字符的索引。

              返回值

              返回指定索引處的字符。

              實例

              public class Test {

              public static void main(String args[]) {

              String s = "www ";

              char result = s.charAt(1);

              System.out.println(result);

              }

              }

              以上程序執(zhí)行結(jié)果為:

              w

              2、public boolean equals(Object anObject)

              參數(shù)

              anObject -- 與字符串進行比較的對象。

              返回值

              如果給定對象與字符串相等,則返回 true;否則返回 false。

              實例

              public class Test {

              public static void main(String args[]) {

              String Str1 = new String("run");

              String Str2 = Str1;

              String Str3 = new String("run");

              boolean retVal;

              retVal = Str1.equals( Str2 );

              System.out.println("返回值 = " + retVal );

              retVal = Str1.equals( Str3 );

              System.out.println("返回值 = " + retVal );

              }

              }

              以上程序執(zhí)行結(jié)果為:

              返回值 = true

              返回值 = true

              3、public boolean endsWith(String suffix)

              endsWith() 方法用于測試字符串是否以指定的后綴結(jié)束。

              參數(shù)

              suffix -- 指定的后綴。

              返回值

              如果參數(shù)表示的字符序列是此對象表示的字符序列的后綴,則返回 true;否則返回 false。注意,如果參數(shù)是空字符串,或者等于此 String 對象(用 equals(Object) 方法確定),則結(jié)果為 true。

              實例

              public class Test {

              public static void main(String args[]) {

              String Str = new String("runooo");

              boolean retVal;

              retVal = Str.endsWith( "run" );

              System.out.println("返回值 = " + retVal );

              retVal = Str.endsWith( "ooo" );

              System.out.println("返回值 = " + retVal );

              }

              }

              以上程序執(zhí)行結(jié)果為:

              返回值 = false

              返回值 = true

              4、public boolean equalsIgnoreCase(String anotherString)

              equalsIgnoreCase() 方法用于將字符串與指定的對象比較,不考慮大小寫。

              參數(shù)

              anObject -- 與字符串進行比較的對象。

              返回值

              如果給定對象與字符串相等,則返回 true;否則返回 false。

              public class Test {

              public static void main(String args[]) {

              String Str1 = new String("run");

              String Str2 = Str1;

              String Str3 = new String("run");

              String Str4 = new String("RUN");

              boolean retVal;

              retVal = Str1.equals( Str2 );

              System.out.println("返回值 = " + retVal );

              retVal = Str3.equals( Str4);

              System.out.println("返回值 = " + retVal );

              retVal = Str1.equalsIgnoreCase( Str4 );

              System.out.println("返回值 = " + retVal );

              }

              }

              以上程序執(zhí)行結(jié)果為:

              返回值 = true

              返回值 = false

              返回值 = true

              5、public String replace(char oldChar,char newChar)

              replace() 方法通過用 newChar 字符替換字符串中出現(xiàn)的所有 oldChar 字符,并返回替換后的新字符串。

              參數(shù)

              oldChar -- 原字符。

              newChar -- 新字符。

              返回值

              替換后生成的新字符串。

              public class Test {

              public static void main(String args[]) {

              String Str = new String("hello");

              System.out.print("返回值 :" );

              System.out.println(Str.replace('o', 'T'));

              System.out.print("返回值 :" );

              System.out.println(Str.replace('l', 'D'));

              }

              }

              以上程序執(zhí)行結(jié)果為:

              返回值 :hellT

              返回值 :heDDo

              6、public String toLowerCase()

              toLowerCase() 方法將字符串轉(zhuǎn)換為小寫。

              參數(shù)

              無

              返回值

              轉(zhuǎn)換為小寫的字符串。

              public class Test {

              public static void main(String args[]) {

              String Str = new String("WWW");

              System.out.print("返回值 :" );

              System.out.println( Str.toLowerCase() );

              }

              }

              以上程序執(zhí)行結(jié)果為:

              返回值 :www

            tags:
            聲明:本站稿件版權(quán)均屬千鋒教育所有,未經(jīng)許可不得擅自轉(zhuǎn)載。
            10年以上業(yè)內(nèi)強師集結(jié),手把手帶你蛻變精英
            請您保持通訊暢通,專屬學習老師24小時內(nèi)將與您1V1溝通
            免費領取
            今日已有369人領取成功
            劉同學 138****2860 剛剛成功領取
            王同學 131****2015 剛剛成功領取
            張同學 133****4652 剛剛成功領取
            李同學 135****8607 剛剛成功領取
            楊同學 132****5667 剛剛成功領取
            岳同學 134****6652 剛剛成功領取
            梁同學 157****2950 剛剛成功領取
            劉同學 189****1015 剛剛成功領取
            張同學 155****4678 剛剛成功領取
            鄒同學 139****2907 剛剛成功領取
            董同學 138****2867 剛剛成功領取
            周同學 136****3602 剛剛成功領取
            相關推薦HOT