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

j.u.regex.Pattern.splitAsStream() doesn't correspond to split() method if using an example from the spec

XMLWordPrintable

    • b110
    • Verified

      Method
      http://download.java.net/jdk8/docs/api/java/util/regex/Pattern.html#splitAsStream%28java.lang.CharSequence%29

      returns a stream with an empty string as the last element if we use an example from

      http://download.java.net/jdk8/docs/api/java/util/regex/Pattern.html#split%28java.lang.CharSequence%29

      Consider the following code:

      -------------------
              Pattern pattern = Pattern.compile("o");

              System.out.println("splitAsStream(..) = " + Arrays.toString(pattern.splitAsStream("boo:and:foo").toArray()));
              System.out.println("split(..) = " + Arrays.toString(pattern.split("boo:and:foo")));
      -------------------


      The output will be

      splitAsStream(..) = [b, , :and:f, ]
      split(..) = [b, , :and:f]


      The following JCK test will fail due to this
      api/java_util/regex/Pattern/index.html#SplitAsStream

            psandoz Paul Sandoz
            dbessono Dmitry Bessonov
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: