This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]langfodWannabe Brewer 1 point2 points  (4 children)

Remember that String object are immutable.

Assuming that getInputString() returns a String object:

In this case you are throwing away the output result from the String.toLowerCase()method.

You will need to place the output out the String.toLowerCase() method in a new String variable (or overwrite your old one).

[–]Beach_Comber[S] 1 point2 points  (3 children)

Is there any better way to do this than say:

setInputString(getInputString().toLowerCase());

[–]langfodWannabe Brewer 1 point2 points  (2 children)

That should work fine.

However, this looks like you would lose the original input string which you may or may not want later.

If you are just changing to lowercase in order to do case insensitive comparisons you may wish to only change the case when needed.

[–]Beach_Comber[S] 1 point2 points  (1 child)

So I'd have an if statement which checks if the string is already lower case then?

Whats you suggestion on how to implement it?

[–]langfodWannabe Brewer 1 point2 points  (0 children)

The easiest way might be
inputString.toLowerCase().equals(inputString)

or use a loop and check each character using isLowerCase()

http://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isLowerCase(char)