0

I add integer values in combo box.When I call getSselectedItem it return object.How i convert it into integer.

4
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by Ezzaral
0

I assume you are after JavaScript, not Java. Anyway with JavaScript values are not strongly typed, so if the values are numbers, you can use "+".

0

I add integer values in combo box.When I call getSselectedItem it return object.How i convert it into integer.

casting it to an Integer. but from your question I take it you want an int, and not an Integer.
so, cast it to a String, and parse that to an int.

for instance, you get back an Object with value = "6";

public int objectToInt(Object givenObject){
  String inString = (String)givenObject;
  return Integer.parseInt(inString);
}

't voila, instant integer-value. this will only work if the value stored in the object is a valid integer value, so if you have any other data in that list, you may want to catch possible exceptions.

0

If you added the items as Integer objects:

int selectedValue = ((Integer)comboBox.getSelectedItem()).intValue();
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.