How to check whether a String contains special characters in Java?

Use the following code in Java to check whether a given String contains any special characters or not.

public boolean isContainsSpecialChar(String toCheck)
{
        boolean isContainsSC = false;
        if (toCheck != null && !toCheck.equals(""))
        {
                Matcher m = Pattern.compile("[\\W]").matcher(toCheck);
                while (m.find())
                {
                        isContainsSC = true;
                        System.out.println(m.start());
                        System.out.println(m.group());
                }
        }
        return isContainsSC;
}

Search