Java_se basic--61. Getting Started with strings

Source: Internet
Author: User

public class Demo1 {public static void main (string[] args) {String str1 = "Hello"; String str2 = "Hello"; String str3 = new String ("Hello"); String STR4 = new String ("Hello"); System.out.println ("Str1==str2?") + (STR1==STR2));  True  System.out.println ("Str2==str3?") + (STR2==STR3));  FalseSystem.out.println ("Str3==str4?") + (STR3==STR4));  FalseSystem.out.println ("Str3.equals (str2)?" + (Str3.equals (STR4))); true//is a string class that overrides the Equals method of object, comparing the contents of two string objects with consistency. the "= =" compares the memory address of two objects when comparing data of reference data types, and the Equals method is also the memory address of two objects by default. }}

Run results

Str1==str2?true
Str2==str3?false
Str3==str4?false
Str3.equals (str2)? True


Text Explanation:


Graphic:



Compare string contents with equals (), compare addresses with = =


AC Penguin: 654249738, and self-taught Exchange group: 517284938

Java_se basic--61. String entry

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.