Is there a Way to converte a Charsequence or a String to an Ingeter?
CharSequence cs = "123"; int number = (int) cs;
I'm a Noob. Solution:
CharSequence cs = "123"; int number = Integer.parseInt(cs);
A CharSequence is a readable sequence of char values. This interface provides uniform, read-only access to many different kinds of char sequences. A char value represents a character in the Basic Multilingual Plane (BMP) or a surrogate. Refer to Unicode Character Representation for details.
A String already is a CharSequence. The String class implements the CharSequence interface. @JeffScottBrown the question actually makes sense, it's a legitimate wonder to anyone reading through the Android or Java doc and missing the detail that CharSequence is not a class.
1.0. interface CharSequence. Represents a readable sequence of Char values.
Use Integer.parseInt()
. If your CharSequence
is not a String
, then you need to convert it first using toString()
.
int number = Integer.parseInt(cs.toString());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With