Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CharSequence to int

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); 
like image 253
passsy Avatar asked May 02 '11 14:05

passsy


People also ask

What is a CharSequence?

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.

Is a String a CharSequence?

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.

What is a CharSequence in Kotlin?

1.0. interface CharSequence. Represents a readable sequence of Char values.


1 Answers

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()); 
like image 140
Joachim Sauer Avatar answered Sep 25 '22 12:09

Joachim Sauer