java.util.Collection with the lowest overhead? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of java.util.Collection with the lowest overhead? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m calling a method in another API that accepts a java.util.Collection of objects. I’ve looked at the method and it immediately copies everything in the collection into a new ArrayList before performing its task.

This got me wondering: What is the absolute lowest overhead Java Collection that I can use to quickly assemble parameters for this method?

Answer

That depends on how it copies the elements, but if it creates the ArrayList-copy like this

new ArrayList<Something>(inputCollection);

or if it does

someCopy.addAll(inputCollection);

then the it will go through the inputCollection.toArray() which is probably best implemented by ArrayList.

We are here to answer your question about java.util.Collection with the lowest overhead? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji