Skip to content

bad example on String reference page #636

@mmalade

Description

@mmalade

Issue description

When I tested the String comparison example given on the String reference page in Processing 3.3.6:

// Comparing String objects, see reference below.
String p = "potato";
if (p == "potato") {
  println("p == potato, yep.");  // This will not print
} 
// The correct way to compare two Strings
if (p.equals("potato")) {
  println("Yes, the contents of p and potato are the same.");
}

Both lines print due to String interning in Java.

URL(s) of affected page(s)

https://processing.org/reference/String.html

Proposed fix

Use a different example:

String a = "good";
String b = "bye";
String c = a + b;

println(c);

if (c == "goodbye") {
  println("The == works"); 
}

if (c.equals("goodbye")) {
  println("The .equals works"); 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions