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

Inconsistent handling of empty string in String.indexOf

XMLWordPrintable

    • merlin
    • generic
    • generic
    • Verified



      Name: krT82822 Date: 09/28/99


      Consider the following program:

      public class StrTest {
          public static void main(String[] args){
              int x1 = "abc".indexOf("",4);
              int x2 = "abc".lastIndexOf("",4);
              System.out.println(x1 + " " + x2);
          }
      }

      when run, it prints:

      -1 3

      This means that indexOf() does not think there is an empty
      string beyond the last character, while lastIndexOf does.
      In order to keep uniformity, indexOf() should deliver the
      same result (3 in the example).

      -----------

      9/28/99 eval1127@eng -- see also 4252047
      (Review ID: 95817)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            kryansunw Kevin Ryan (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: