What would be the simplest way to convert List<Integer> to List<String>
objects. Currently I iterate through all the integers and add them to a List<String> objects
, is there a utility function which is already available?
You found a simple way. The type are "incompatible", so you need a conversion rule anyway (which is simple in your case). The algorithm will always be O(n), regardless of iterating through the collections manually or calling some API method from some 3rd party library (JRE doesn't offer API for your task).
While there are some libraries that can do general List
transformations (like Google's Guava) using one for this case probably won't save you any lines of code as you'd need to create a Function
object, and that alone involves so much boilerplate that your existing code is probably smaller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With