十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
public class StringTest{ public static void main(String[] args){ //1 String s1 = "abc"; //2 String s2 = new String("cdg"); //3 byte[] bytes={98,88,34,25}; String s3 = new String(bytes); //4String(byte[] bytes, int offset, int length)Constructs a new String by decoding the specified subarray of bytes using the platform's default charse; String s4 = new String(bytes,1,3); //5. char[] c1 = {'我','是','中','国','人'}; String s5 = new String(c1); System.out.println(s5); //我是中国人 //6. String s6 = new String(c1,2,2); System.out.println(s6); //中国System.out.println(s3); //abcd String已经重写了Object中的toString } } /*字符串常用方法 */ public class StringTest06{ public static void main(String[] args){ //1.char charAt(int index); String s1 = "我是王勇,是坏人!"; char c1 = s1.charAt(2); System.out.println(c1); //王 //2.boolean endsWith(String endStr); System.out.println("HelloWorld.java".endsWith("java")); //true System.out.println("HelloWorld.java".endsWith(".java")); //true System.out.println("HelloWorld.java".endsWith("HelloWorld.java")); //true System.out.println("HelloWorld.java".endsWith("txt")); //false System.out.println("HelloWorld.java".endsWith("java ")); //false //3. boolean equalsIgnoreCase(String anotherString); System.out.println("abc".equalsIgnoreCase("ABc")); //true //4.byte[] getBytes(); byte[] bytes = "abc".getBytes(); for(int i=0;i
文章名称:String的构造方法和一般方法
网站路径:http://shouzuofang.com/article/gesged.html