May
May

Reputation: 73

Multiple methods in one string?

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

Answers (3)

NPE
NPE

Reputation: 500465

Use Character.toLowerCase() followed by String.valueOf():

outputLabel.setText(String.valueOf(Character.toLowerCase(firstname.charAt(0))));

Upvotes: 5

Ayush
Ayush

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

AlexR
AlexR

Reputation: 115358

Something like this:

str.toLowerCase().charAt(0)

This converts whole line to lower case and takes the first character.

Upvotes: 0

Related Questions