Rotate user input string to uppercase Java

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

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

For the above snippet of code fo, how would I format the data that the user entered to be all capitals?

Any help here would be appreciated.

+6
source share
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(); 
+8
source

See String.toUpperCase ()

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

+8
source

Source: https://habr.com/ru/post/914152/


All Articles