ToLowerCase with special / unicode characters throws an exception

correct me if I am wrong.

If str has a character of type " " in it, then:

 str.toLowerCase(Locale.English); 

throws a null pointer exception. This is the behavior that I see.

So what's the deal? What's happening? It is not indicated that toLowerCase throws a null pointer exception.

Is there an easy way around this? I need str to be lowercase in order to be able to use case insensitive, contains a check with a different string, but I need a string containing these characters so that it displays correctly.

What would you say is the most effective solution if there is no “easy way?”

0
java string unicode
Jul 27 '09 at 19:49
source share
2 answers

Instead of converting to lower case, I would suggest trying String object equalsIgnoreCase() method .

Although, as the comments say, there is no reason for the toLowerCase() function to throw a null pointer exception if the parameter is non-zero. I would either use a debugger to check the status of str , or wrap the call toLowerCase() in an if , and if str is null, do something (e.g. throw an exception, print an expression, write a message) and not make a function call .

+2
Jul 27 '09 at 19:52
source share

Hmm, this works for me:

 String upper = new String("asdCSD4rSDFSDFS•••••••••XCj"); String lower = upper.toLowerCase(Locale.ENGLISH); System.out.println("Lower " + lower); Lower asdcsd4rsdfsdfs•••••••••xcj 
+2
Jul 27 '09 at 19:57
source share



All Articles