Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(guide): Fix incorrect code in Java Strings #27399

Merged
merged 1 commit into from
Oct 24, 2018

Conversation

Manish-Giri
Copy link
Contributor

Incorrect Code

String str = "Hello world";
String str2 = "Hello world";

System.out.println(str == str2); // This prints false
System.out.println(str.equals(str2); // This prints true

Using == to compare String objects checks references to the two objects, and in this case, those two references point to the same string object created in the String Pool. Hence this returns true, and not false, as is incorrectly stated in the guide.

Also fixed formatting.

  • I have read freeCodeCamp's contribution guidelines.
  • My pull request has a descriptive title (not a vague title like Update index.md)
  • My pull request targets the master branch of freeCodeCamp.
  • None of my changes are plagiarized from another source without proper attribution.
  • My article does not contain shortened URLs or affiliate links.

Using `==` to compare String objects checks references to the two objects, and in this case, those two references point to the same string object created **in the String Pool**. Hence this returns `true`, and not `false`, as is incorrectly stated in the guide.

Also fixed formatting.
@Manish-Giri Manish-Giri requested review from raisedadead and removed request for raisedadead October 24, 2018 08:56
@Manish-Giri Manish-Giri added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Oct 24, 2018
@raisedadead raisedadead merged commit 164f165 into master Oct 24, 2018
@raisedadead raisedadead deleted the Manish-Giri-java-strings branch October 24, 2018 10:28
vdkhadke pushed a commit to vdkhadke/freeCodeCamp that referenced this pull request Oct 28, 2018
Using `==` to compare String objects checks references to the two objects, and in this case, those two references point to the same string object created **in the String Pool**. Hence this returns `true`, and not `false`, as is incorrectly stated in the guide.

Also fixed formatting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants