资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

String的构造方法和一般方法

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://cdkjz.cn/article/gesged.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220