Commit eb38b63c authored by Trisha Gee's avatar Trisha Gee
Browse files

[appB] More examples for String immutability

parent 2cbb75b5
Loading
Loading
Loading
Loading
+18 −0
Changes for src/main/java/appB/StringImmutability.java: 18 added lines, 0 removed lines.
Original line number Diff line number Diff line
package appB;

public class StringImmutability {
  public static void main(String[] args) {
    stringMethodsCreateNewObjects();
  }

  static void stringMethodsCreateNewObjects() {
    String string = "the text";
    String upperStr = string.toUpperCase();

    System.out.println(string);
    System.out.println(upperStr);
    System.out.println(string.equals(upperStr));
  }

  static void stringsOfTheSameValueAreTheSameObject() {
    String str1 = "customer";
    String str2 = "customer";
    System.out.println(str1 == str2);
  }
  String stringConcatenation() {
    String s = "0";
    for (int i = 1; i < 10; i++) {