Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 669
user1081326 Avatar asked Apr 25 '12 16:04

user1081326


2 Answers

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

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

JOptionPane.showInputDialog("Enter name: ").toUpperCase();
like image 52
gregdferrell Avatar answered Sep 20 '22 19:09

gregdferrell


See String.toUpperCase()

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

like image 42
ControlAltDel Avatar answered Sep 23 '22 19:09

ControlAltDel