user1081326
user1081326

Reputation: 425

Turn a User Input String to Upper Case Java

This may seem like a silly question, but after going through pages of google, i havnt been able to find the answer i want.

s1.setName(JOptionPane.showInputDialog("Enter Name: ");

For the above piece fo code, how would i format the data the user entered to be all capitals?

Any help here would be appreciated.

Upvotes: 7

Views: 33782

Answers (2)

gregdferrell
gregdferrell

Reputation: 290

The String class has a toUpperCase() method on it.

JOptionPane.showInputDialog(..) returns a String, so you can use:

JOptionPane.showInputDialog("Enter name: ").toUpperCase();

Upvotes: 9

ControlAltDel
ControlAltDel

Reputation: 35011

See String.toUpperCase()

Remember that String is immutable, so this creates a duplicate string

Upvotes: 8

Related Questions