Skip to main content

Any remarks on 6307387: Add String.endsWithIgnoreCase(String suffix)?

4 replies [Last post]
Joined: 2003-06-10


Bug ID 6307387: Add String.endsWithIgnoreCase(String suffix)
This report and suggested implementation came in on the 'jdk-collaboration' channel [1].

Since this is an RFE rather than a bug fix, the RE (Responsible Engineer: a domain expert in this area) is pushing back on the request. The question is: would this addition would 'carry its own weight' [2] without adding unused clutter and complexity to the language and the test suite. Of course, making this method part of the API would require adding compatability and functionality tests to cover it.

So: we are interested in starting a discussion here. Would you use String.endsWithIgnoreCase(String suffix), or not? If you could spend a dollar on adding new methods to the next JDK release, how much would you spend on Bug 6307387?

Looking forward to hearing from you-




Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-10

As illustrated by the RFE it seems that the major use of this is to test for file extensions. This seems to be inappropriate; the test ought to be case insensitive only where the platform's file system is case insensitive.

However what is really required is a mechanism for testing a file's type. On Windows this might well involve a case insensitive comparison of extensions, while other systems may maintain type independently of the name (as an attribute).

However please don't add this to the black hole that is JSR-203 (formerly JSR51).

See bug 4039759, which has unfortunately been closed in favour of the previously mentioned black hole. Although it is unclear whether JSR-203 still contains relevant objectives.

Message was edited by: mthornton

Joined: 2003-06-18

Is the RE proposing that toLowerCase().endsWith(...) is equivalent?

In that case I would agree with the RE unless there is some kind of significant, important (eg. Real World) performance case where endsWithIgnoreCase(...) could be usefully optimized.

I think such a Real World case should be established first.

Joined: 2003-06-19

You mean toLowerCase(Locale.US).endsWith(...).

Even then, the ignores-case methods check both upper and lower cases.

Also of note, String.toUpperCase transforms the eszet and scores of others into multiple characters. Presumably future characters could mess with String.toLowerCase.

Joined: 2003-06-19

Seems a somewhat obscure case to make it into java.lang.

Grep for regionMatches on your favourite source base, and see how many ends-withs you find. There's some in Xerces XPath regexs.

If you introduce endsWithIgnoreCase, should you not also add containsIgnoreCase, contentsEqualsIgnoreCase (*2), endsWithIgnoreCase, indexOfIgnoreCase (*4), lastIndexOfIgnoreCase(*4), replaceIgnoreCase and startsWithIgnoreCase (*2). And perhaps StringBuffer.indexOfIgnoreCase (*2) and lastIndexOfIgnoreCase (*2).

There is also some confusion with String.toUpperCase giving a different length and the Turkish I. How many cases are there in the JRE of getting the latter wrong?