I presume you mean alternative. I think you are right to say your method works, but it can be improved, so I don't think an alternative is necessary.
That second method of yours (lines 13‑15) behaves rather like a function and should probably be marked static final. In that case you must also pass the number to be formatted as an argument. If the number is a
long, always append the final L: 8123
L. Don't use l because I can see the earlier number as 81231. You now have this sort of method
As for the warning from the
IDE etc. There comes a time when you have to bite the bullet and tell the IDE you do know what you are doing and I am going to ignore that warning
I you write yourself a utility class, you can put that method in the utility class and keep it for ever.