String s1, s2, s3; s1 = "Hello World"; s2 = "Goodbye"; s3 = "World";
String s4 = s2 + ' ' + s3; // s4 now stores "Goodbye World"
String s5;
s5 = String.format("Pi to 3 decimal places = %.3f", Math.PI);
void showMessageDialog(Component parentComponent, Object message)
void showMessageDialog(Component parentComponent, Object message,
String title, int messageType)
void showMessageDialog(Component parentComponent, Object message,
String title, int messageType, Icon icon)
String s1;
s1 = JOptionPane.showInputDialog("Please enter an integer:");
String s1;
s1 = JOptionPane.showInputDialog("Please enter an integer:");
int value = Integer.parseInt(s1); // converts s1 into an integer
| Primitive type | Corresponding wrapper class | static conversion method |
|---|---|---|
| boolean | Boolean | boolean parseBoolean(String) |
| byte | Byte | byte parseByte(String) |
| short | Short | short parseShort(String) |
| int | Integer | int parseInt(String) |
| long | Long | long parseLong(String) |
| float | Float | float parseFloat(String) |
| double | Double | double parseDouble(String) |
int ans = JOptionPane.showConfirmDialog(null, "Are you a good student?",
"Student query", JOptionPane.YES_NO_OPTION);
if (ans == JOptionPane.YES_OPTION)
JOptionPane.showMessageDialog(null, "Hurrah! A good student!");
else
JOptionPane.showMessageDialog(null, "Not another bad student!");