Implement a case insensitive contains() method for Java String class

Writing by on Friday, 12 of November , 2010 at 12:57 pm

One simple solution is to convert both strings to lower case and then use the contains() method.

public boolean containsIgnoreCase(String longString, String shortString) {
    return (longString.toLowerCase().contains(shortString.toLowerCase()));
}

Leave a comment

Category: Java

No Comments

No comments yet.

Leave a comment

You must be logged in to post a comment.

Shivdev Kalambi's Blog

Shivdev Kalambi is a Software Development Manager, previously a Principal Software Engineer at ArcSight/HP. With over 16 years' experience in software development, he's worked on several technologies and played different roles and contributed to all phases of projects. Non-tech activies include Ping-pong, Rock Climbing and Yoga at PG, Golf, Skiing, Swimming & a beer enthusiast.