RFR: 8303266: Prefer ArrayList to LinkedList in JImageTask

Stuart Marks smarks at openjdk.org
Wed Mar 1 22:51:12 UTC 2023


On Mon, 27 Feb 2023 11:33:38 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

> `LinkedList` is used as a field `jdk.tools.jimage.JImageTask.OptionsValues#jimages`
> It's created, filled (with `add`) and then iterated. No removes from the head or something like this. `ArrayList` should be preferred as more efficient and widely used (more chances for JIT) collection.

Sorry, there was a markup error in my earlier comment. What I meant it to say was this:

« If you want people to stop using LinkedList, it will be much more effective to get _your favorite tutorial site_ to say "use ArrayList instead of LinkedList" instead of trying to remove uses of it from the JDK. »

(I had put the italicized text in angle brackets, which I guess were interpreted as malformed markup and so the text was simply dropped.)

I might as well name names here. If you do a web search for "java LinkedList" you will get hits on the usual top tutorial sites. One of them is this:

https://www.w3schools.com/java/java_linkedlist.asp

The whole discussion of "ArrayList vs. LinkedList" here is incredibly superficial. The summary is this:

> Use an ArrayList for storing and accessing data, and LinkedList to manipulate data.

This sort of statement is a lot more influential in getting Java developers to use LinkedList than anything the JDK does. Orders of magnitude more Java developers look at these tutorial sites than look at obscure corners of the JDK source code. If you want people to stop using LinkedList, it would be better to try to get those tutorial sites changed than to try to eradicate LinkedList from the JDK.

-------------

PR: https://git.openjdk.org/jdk/pull/12760


More information about the core-libs-dev mailing list