Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 227
some_other_guy Avatar asked Sep 02 '25 05:09

some_other_guy


1 Answers

int i = 1234;
char[] chars = ("" + i).toCharArray();
like image 137
AlexR Avatar answered Sep 04 '25 19:09

AlexR