How do I replace the first three characters of a Java integer by 111?

Alex Admin :

I have an integer in java. How do I replace its’ first three numbers with 111(or any other number), for example turning 783729 into 111729? Many thanks!

Kaimson :

You could convert it into a string and then replace the first three letters.

String s = String.valueOf(783729);
int i = Integer.parseInt(s.replace(s.substring(0, 3), "111"));

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=403375&siteId=1