"Java" Caesar Encryption and After-class hands-on brain

Source: Internet
Author: User

1. Code and running results

in the In java, a string constant with the same content ("Hello") holds only one copy to conserve memory, so s0,s1,s2 actually refers to the same object.

When the compiler compiles a s2 sentence, It strips out the "+" number and connects the two strings directly to a string ("Hello"). This optimization work is done automatically by the Java Compiler.

When you create a string object directly using the new keyword, the value is the same (all "Hello"), but it is still two separate objects.

2. Code and running results

Assigning a value to a string variable means: two variables (s1,s2) now references the same string object "a"!

The contents of the string object are read-only, and the value of the S1 variable is modified with "+", in effect, a new string object is obtained with the content "ab", which is independent of the object "a" referenced by the original s1, so S1==s2 returns false;

The "ab" string in the code is a constant that refers to a string that is not related to the "ab" object referenced by s1.

The String.Equals () method can compare the contents of a two String.

3. Code and running results

The String.Equals () method compares the value of two strings, not the Address.

"Java" Caesar Encryption and After-class hands-on brain

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.