I was looking for a program that could return only numbers from a string containing letters and numbers and found the code below.
The program works perfectly, but introduces Character.
To my understanding char is a single letter, number or any other sign in java, but I have never heard of Character. Is it the same as char or is it completely different? How do I use it (other than the way shown below)?
and what do I need to do if I want the print in int?
String something = "423e";
int length = something.length();
String result = "";
for (int i = 0; i < length; i++) {
Character character = something.charAt(i);
if (Character.isDigit(character)) {
result += character;
}
}
System.out.println("result is: " + result);