Object obj = GetObject ();
if (obj instanceof Integer)
int value = (Integer) obj;
A method of converting a string to type int:
1. Integer.parseint ([String])
2.integer.valueof ([String]). Intvalue ();
3.integer.decode ([String]): Decodes the String to an Integer. Accepts decimal, hexadecimal, and octal digits given by the following syntax
For example:
int A=integer.decode ("0144"); Octal conversion result is 100
int B=integer.decode ("123");//Decimal conversion result is 123
int C=integer.decode ("0x123");//16 binary conversion result is 291
Note: Integer.decode ([string]) plus minus sign can also be converted, but the string cannot have spaces. Otherwise, report NumberFormatException exception.
Note: The string is converted to Double, Float, and Long in a similar way.
convert int to String type method:
1.String s = string.valueof (i);
2.String s = integer.tostring (i);
3. String s = "" + I;
Not commonly used:
1.integer.tobinarystring (int i): Returns a string representation of an integer parameter as a binary (radix 2) unsigned integer.
2.integer.tohexstring (int i): Returns the string representation of an integer parameter as a 16-based (radix 16) unsigned integer.
3.integer.tooctalstring (int i): Returns the string representation of an integer parameter as a eight-based (radix 8) unsigned integer.
Note: Double, Float, Long turn into a string in a similar way.
The object type is converted to the int type:
1. If object is generated by the Byte,short,int,char type, then it is OK to assign the value directly without conversion.
2. If object is generated as a string type, first convert the object to a string type, and then convert the string type to the int type.
For example.
String myint= "123";
Object Os=myint;
int B=integer.parseint ((String) OS);//can also os.tostring ()
3. If object is generated by the Float,double,long type, the idea is to convert the object to the corresponding data type and then to the int type.
The object type is converted to String type:
String title=string.valueof (obj[2]);
String content=string.valueof (obj[3]);
The object type is converted to the date type:
SimpleDateFormat can either convert a string to date or date to string.
. Parse (String)
. Format (Date)
That
SimpleDateFormat sdf=new SimpleDateFormat ("Yyyy-mm-dd");
String Indate=sdf.format (date);
Date Indate=sdf.parse (String);
If you use Spinnerdatemodel.
You can try to cast this object directly to date.
Date date = (date) object;
--------------------------------------------------------------------------------------------
Transferred from: http://www.cnblogs.com/1020182600HENG/p/6137206.html
Object in Java converted to int or string type method