Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1230267

the concat() method in java.lang.String won't succeed with a substring as an arg

XMLWordPrintable

    • sparc
    • solaris_2.4

      [vbo 12/4/95]

      The string returned from a substring() call cannot be successfully used as an argument
      to the concat() call on another string. The following short program demonstrates the
      problem.

      ---- Bug.java ----

      class Bug {
          public static void main(String argv[]) {
              String s1 = new String("012345678901234567890..25...30...35");
              String s2 = new String("Numbers will be concatenated here: ");

              // it seems you can't concatenate a substring
              s2.concat(s1.substring(0, 21));
              System.out.println(s2);

              // here's a workaround
              s2 = s2 + s1.substring(0, 21);
              System.out.println(s2);
          }
      }


      ---- output of above ----

      (vbo) rootbeer other> javac Bug.java
      0 errors
      (vbo) rootbeer other> java Bug
      Numbers will be concatenated here:
      Numbers will be concatenated here: 012345678901234567890

            apalanissunw Anand Palaniswamy (Inactive)
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: