新网创想网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
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://wjwzjz.com/article/gesged.html