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

RFE: Add method boolean String.contains(String substring)

XMLWordPrintable

    • tiger
    • x86
    • windows_98



      Name: jl125535 Date: 12/11/2002


      FULL PRODUCT VERSION :
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_01-b03)
      Java HotSpot(TM) Client VM (build 1.4.0_01-b03, mixed mode)

      FULL OPERATING SYSTEM VERSION :

      All.

      ADDITIONAL OPERATING SYSTEMS :

      All.

      A DESCRIPTION OF THE PROBLEM :
      Quite frequently I would like to check whether one String
      contains another as a substring, without caring where the
      substring occurs. I can use <code>boolean contains =
      (str1.indexOf(str2) > -1);</code>, but this is inelegant,
      especially for a frequent idiom. I would prefer a method in
      String which checked this for me.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Look through the String API. Observe that none of the
      methods with return type boolean do this.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      Expected such a method to exist. It doesn't.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER WORKAROUND :
      boolean contains = (str1.indexOf(str2) > -1);

      (Alternatively, hack rt.jar, but I don't think the licence
      allows this).
      (Review ID: 164276)
      ======================================================================

            mmcclosksunw Michael Mccloskey (Inactive)
            jleesunw Jon Lee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: