Turn a User Input String to Upper Case Java

不羁的心 提交于 2019-12-04 01:16:33

问题


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.


回答1:


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

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

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



回答2:


See String.toUpperCase()

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



来源:https://stackoverflow.com/questions/10320200/turn-a-user-input-string-to-upper-case-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!