Reputation: 73
I want to use two methods for one string somewhat like this
outputLabel.setText(firstname.charAt(0) + toLowerCase());
How can I get it to return the character at a certain position and also convert the string to lowercase?
I want the output to be a single character, converted to lower case, and on a single line.
Many thanks!
Upvotes: 0
Views: 4206
Reputation: 500465
Use Character.toLowerCase()
followed by String.valueOf()
:
outputLabel.setText(String.valueOf(Character.toLowerCase(firstname.charAt(0))));
Upvotes: 5
Reputation: 42450
Chain them like this:
outputLabel.setText(firstname.toLowerCase().charAt(0))
You cannot do it the other way around, because .toLowerCase()
does not work on characters which is what charAt()
returns.
Upvotes: 2
Reputation: 115358
Something like this:
str.toLowerCase().charAt(0)
This converts whole line to lower case and takes the first character.
Upvotes: 0