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);
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);
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());
Since Java 9 you can use Integer.parseInt(CharSequence s, int from, int to, int radix) to parse integers from any CharSequence without first converting it to a String:
CharSequence cs = new StringBuilder("4711");
int value = Integer.parseInt(cs, 0, cs.length(), 10);
Use the parsers from the Wrapper classes (Integer, Float, etc)...
public static void main(String[] args) {
String s = "1";
int i = Integer.parseInt(s);
System.out.println(i);
}
From Editview component,
TextView txtYear = (TextView) findViewById(R.id.txtYear);
int intYear = Integer.parseInt(txtYear.getText().toString());