Preferred:
String x = JComboBox.getSelectedItem().toString();
or
String x = String.valueOf(JComboBox.getSelectedItem());
The second method protects against null values as well.
Avoid using casting:
String x = (String)JComboBox.getSelectedItem();
This would work fine if the item is indeed a string, but will fail if it can (also) be any other data type. To be safe, use either of the first two methods.
Send a link to this post to yourself or a friend.