javaarrayscastingtype-conversion

Convert an integer to an array of characters : java


What is the best way to convert an integer into a character array?

Input: 1234

Output: {1,2,3,4}

Keeping in mind the vastness of Java language what will be the best and most efficient way of doing it?


Solution

  • int i = 1234;
    char[] chars = ("" + i).toCharArray();