I try to convert a CharacterSequence directly into a integer array with the single integers.
CharSequence nbr = "478";
int j;
int[] testArray = new int[100];
for(j = 0; j <= nbr.length() - 1; j++)
testArray[j] = Character.getNumericValue(nbr.charAt(j));
System.out.println(testArray);
Instead of the desired [4,7,8] the Console gives back something like that:
[I@424c2849
Setting up a switch with the cases ‘0’,’1′,…,’8′,’9′ and corresponding assignment did not solve the problem.
I hope you can help me! Thanks in advance 😉
Arrays don’t override the
toStringmethod. So, when you try to print any array, theObjectclasstoStringmethod is invoked, and you get the representation returned by that method, which is of the form –Type@hashCodeTo get the required representation, use
Arrays.toStringmethod to print array: –Apart from that, you really should declare your integer array as:
rather than using
100size.