Reputation: 6371
I am new to java dev. I want to add numbers in an editText. i.e if user types in 15 in editText, it should add the numbers 1 + 5 giving the result 6. Is there a function for it in java. In C# it is ToCharArray() but I don't know what it's called in java. Thanks
Upvotes: 0
Views: 114
Reputation: 108957
you can use
String str = "15";
char[] cArray = str.toCharArray();
int sum = 0;
for (char c : cArray)
sum += Character.digit(c, 10);
Upvotes: 1
Reputation: 81694
When translating between C# and Java, you can get very far by doing nothing more than changing the capitalization. The equivalent method in Java's String class is "toCharArray()", starting with a lower-case "t".
Upvotes: 1