Curious to know if there's a more elegant way of trying to find the sum of digits at odd positions in a string in Java 8.
This is currently my function
/**
* Explode string into char array, get sum of ASCII values at odd positions and divide by 10 to convert
* to the integer value from that character
* @param ccNumber string
* @return int sum
*/
int calculateSumOfOddDigits(final String ccNumber) {
final char[] digits = ccNumber.toCharArray();
return (digits[0] + digits[2] + digits[4] + digits[6] + digits[8] + digits[10] + digits[12] + digits[14]) / 10;
}
Still not familiar with Streams and Java 8 and thought maybe you could do it like so:
ccNumber.chars().mapToObj(x -> (char) x {
..add odd position digits
})
Any suggestions welcome.