Java 字符串 之 String 赋值比较

简介:

http://www.verejava.com/?id=16993012522383

/**
    字符串 String
    1. 字符串的赋值和初始化
    2. 字符串的比较
    3. 字符串的内存结构
    4. 字符串操作的性能问题
*/
public class TestString {
    
    public static void main(String[] args) {
        //字符串的赋值和初始化两种形式
        //    1. 直接赋值
        //    2. new String() 实例化赋值
        String str = "hello";
        String str1 = new String("hello");
        System.out.println(str);
        System.out.println(str1);

        System.out.println("\n----------------");
        //字符串的比较
        //    1. 引用比较 ==
        //    2. 值比较 equals
        String str3 = "hello";
        String str4 = new String("hello");
        String str5 = new String("hello");
        String str6 = "hello";
        System.out.println(str3 == str4);
        System.out.println(str3.equals(str4));
        System.out.println(str4 == str5);
        System.out.println(str3 == str6);

    }
}

http://www.verejava.com/?id=16993012522383

目录
相关文章
|
7天前
|
SQL JSON Java
告别字符串拼接:用Java文本块优雅处理多行字符串
告别字符串拼接:用Java文本块优雅处理多行字符串
198 108
|
14天前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
200 100
|
14天前
|
开发者 Python
Python中的f-string:高效字符串格式化的利器
Python中的f-string:高效字符串格式化的利器
238 99
|
17天前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
|
17天前
|
开发者 Python
Python f-string:高效字符串格式化的艺术
Python f-string:高效字符串格式化的艺术
|
2月前
|
Python
Python中的f-string:更简洁的字符串格式化
Python中的f-string:更简洁的字符串格式化
217 92
|
3月前
|
自然语言处理 Java Apache
在Java中将String字符串转换为算术表达式并计算
具体的实现逻辑需要填写在 `Tokenizer`和 `ExpressionParser`类中,这里只提供了大概的框架。在实际实现时 `Tokenizer`应该提供分词逻辑,把输入的字符串转换成Token序列。而 `ExpressionParser`应当通过递归下降的方式依次解析
234 14
|
4月前
|
存储 编译器 C语言
关于string的‘\0‘与string,vector构造特点,反迭代器与迭代器类等的讨论
你真的了解string的'\0'么?你知道创建一个string a("abcddddddddddddddddddddddddd", 16);这样的string对象要创建多少个对象么?你知道string与vector进行扩容时进行了怎么的操作么?你知道怎么求Vector 最大 最小值 索引 位置么?
82 0
|
7月前
|
缓存 安全 Java
《从头开始学java,一天一个知识点》之:字符串处理:String类的核心API
🌱 **《字符串处理:String类的核心API》一分钟速通!** 本文快速介绍Java中String类的3个高频API:`substring`、`indexOf`和`split`,并通过代码示例展示其用法。重点提示:`substring`的结束索引不包含该位置,`split`支持正则表达式。进一步探讨了String不可变性的高效设计原理及企业级编码规范,如避免使用`new String()`、拼接时使用`StringBuilder`等。最后通过互动解密游戏帮助读者巩固知识。 (上一篇:《多维数组与常见操作》 | 下一篇预告:《输入与输出:Scanner与System类》)
154 11

热门文章

最新文章