Search code examples
javaandroidintcharsequence

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);

Solution

  • 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());