字符串

package com.hanqi;

public class 字符串 {

    public static void main(String[] args) {
        // string
        String str="字符串常量";
        char[]c=new char[]{'我','很','好'};
        String str3=new String(c);
        String str1=new String();//构造方法
        String str2=new String("字符串");//new开辟新的内存空间
        System.out.println("str="+str);
        System.out.println("str2="+str2);
        System.out.println("str1和str2是否=="+(str1==str2));
        //==运算,比较的是内存地址是否相等
        System.out.println("str1和str2是否相同:"+str1.equals(str2));
        //字符串信息
        System.out.println("字符串长度="+str.length());
        //查找字符串中子字符串的位置,返回找到后的首字的索引值
        System.out.println("常字的位置="+str.indexOf("常"));
        

    }

}
原文地址:https://www.cnblogs.com/yangchengyu314/p/5227941.html