Substring replacement. : String Concatenation « Data Type « Java Tutorial






class StringReplace {
  public static void main(String args[]) {
    String org = "This is a test. This is, too.";
    String search = "is";
    String sub = "was";
    String result = "";
    int i;

    do { // replace all matching substrings
      System.out.println(org);
      i = org.indexOf(search);
      if (i != -1) {
        result = org.substring(0, i);
        result = result + sub;
        result = result + org.substring(i + search.length());
        org = result;
      }
    } while (i != -1);

  }
}








2.22.String Concatenation
2.22.1.String concatenation: '+' operation generates a new String object
2.22.2.String concatenation: The + contains null
2.22.3.String concatenation: Convert an integer to String and join with two other strings
2.22.4.String concatenation: Combining a string and integers
2.22.5.String concatenation: Combining integers and a string
2.22.6.Substring replacement.
2.22.7.Pad string
2.22.8.Padded String
2.22.9.Return a string padded with the given string for the given count.