howcanicastanobjecttoanintinjava?
if you ' resurethatthisobjectisaninteger :
intI=(integer ) object;
Or,starting from Java 7,you can equivalently write:
intI=(int ) object;
Beware,itcanthrowaclasscastexceptionifyourobjectisn ' tanintegerandanullpointerexceptionifyourobjectisnull。
thiswayyouassumethatyourobjectisaninteger (thewrappedint ) and you unbox it into an int。
intisaprimitivesoitcan ' tbestoredasanobject,theonlywayistohaveanintconsidered/boxedasanintegerthenstoredasanobject。
If your object is a String,thenyoucanusetheinteger.value of (methodtoconvertitintoasimpleint 3360
inti=integer.value of ((字符串) object;
itcanthrowanumberformatexceptionifyourobjectisn ' treallyastringwithanintegerascontent。
资源:
On the same topic :