Turn a User Input String to Upper Case Java

2019-02-17 09:26发布

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.

2条回答
小情绪 Triste *
2楼-- · 2019-02-17 10:12

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

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

JOptionPane.showInputDialog("Enter name: ").toUpperCase();
查看更多
Emotional °昔
3楼-- · 2019-02-17 10:26

See String.toUpperCase()

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

查看更多
登录 后发表回答