<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: When to use LinkedList? Never?</title>
	<atom:link href="http://almaer.com/blog/when-to-use-linkedlist-never/feed" rel="self" type="application/rss+xml" />
	<link>http://almaer.com/blog/when-to-use-linkedlist-never</link>
	<description>blogging about life, the universe, and everything tech</description>
	<lastBuildDate>Sat, 08 Sep 2012 07:06:53 -0700</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Stephen Colebourne</title>
		<link>http://almaer.com/blog/when-to-use-linkedlist-never/comment-page-1#comment-24260</link>
		<dc:creator>Stephen Colebourne</dc:creator>
		<pubDate>Wed, 13 Jul 2005 20:44:07 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/when-to-use-linkedlist-never#comment-24260</guid>
		<description>See also TreeList in Commons Collections:
http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/org/apache/commons/collections/list/TreeList.html
for a different approach at an ArrayList alternative thats good at insert/remove in the middle.
</description>
		<content:encoded><![CDATA[<p>See also TreeList in Commons Collections:<br />
<a href="http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/org/apache/commons/collections/list/TreeList.html" rel="nofollow">http://jakarta.apache.org/commons/collections/apidocs-COLLECTIONS_3_1/org/apache/commons/collections/list/TreeList.html</a><br />
for a different approach at an ArrayList alternative thats good at insert/remove in the middle.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jukka Lindstr&#246;m</title>
		<link>http://almaer.com/blog/when-to-use-linkedlist-never/comment-page-1#comment-24259</link>
		<dc:creator>Jukka Lindstr&#246;m</dc:creator>
		<pubDate>Wed, 13 Jul 2005 14:08:20 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/when-to-use-linkedlist-never#comment-24259</guid>
		<description>so all in all:

add(i, object) is O(n) for both ArrayList and LinkedList in the worstcase. O(1) for the best case (last position for ArrayList or last &amp; first positions for LinkedList).

get(i) is O(1) for ArrayList and O(n) for LinkedList. So conclutions ? Well, choosing the list type beforehand is premature optimization I say ;).


</description>
		<content:encoded><![CDATA[<p>so all in all:</p>
<p>add(i, object) is O(n) for both ArrayList and LinkedList in the worstcase. O(1) for the best case (last position for ArrayList or last &#038; first positions for LinkedList).</p>
<p>get(i) is O(1) for ArrayList and O(n) for LinkedList. So conclutions ? Well, choosing the list type beforehand is premature optimization I say ;).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jukka Lindstr&#246;m</title>
		<link>http://almaer.com/blog/when-to-use-linkedlist-never/comment-page-1#comment-24258</link>
		<dc:creator>Jukka Lindstr&#246;m</dc:creator>
		<pubDate>Wed, 13 Jul 2005 13:57:36 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/when-to-use-linkedlist-never#comment-24258</guid>
		<description>Well, the test case only tests the &quot;best-case&quot; for arraylists, since it removes the element immediately after the insert.

if you try the same test case just with adds only (and wrap the &#039;ar&#039; variable into new ArrayList(ar) before passing it to the test methods), you&#039;ll get quite a different results:

beginning ArrayList took 1252
beginning LinkedList took 10
middle    ArrayList took 751
middle    LinkedList took 2474
end       ArrayList took 0
end       LinkedList took 0

The problem with ArrayList at the beginning and end is that it has to System.arraycopy the remainder of the list and possibly allocate new array for the elements if the existing array is not big enough for the elements. Adding to middle of linked list is slow because it has to iterate to the given position.
</description>
		<content:encoded><![CDATA[<p>Well, the test case only tests the &#8220;best-case&#8221; for arraylists, since it removes the element immediately after the insert.</p>
<p>if you try the same test case just with adds only (and wrap the &#8216;ar&#8217; variable into new ArrayList(ar) before passing it to the test methods), you&#8217;ll get quite a different results:</p>
<p>beginning ArrayList took 1252<br />
beginning LinkedList took 10<br />
middle    ArrayList took 751<br />
middle    LinkedList took 2474<br />
end       ArrayList took 0<br />
end       LinkedList took 0</p>
<p>The problem with ArrayList at the beginning and end is that it has to System.arraycopy the remainder of the list and possibly allocate new array for the elements if the existing array is not big enough for the elements. Adding to middle of linked list is slow because it has to iterate to the given position.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tom Hawtin</title>
		<link>http://almaer.com/blog/when-to-use-linkedlist-never/comment-page-1#comment-24257</link>
		<dc:creator>Tom Hawtin</dc:creator>
		<pubDate>Wed, 13 Jul 2005 13:38:50 +0000</pubDate>
		<guid isPermaLink="false">http://almaer.com/blog2/when-to-use-linkedlist-never#comment-24257</guid>
		<description>If you look in java.util.Collections (the utility class), there&#039;s a set of constants where it switches over algorithms between index-based and iterator-based for non-RandomAccess lists. It&#039;s interesting to see how large some of those numbers are, particularly with the low cost of memory allocation for the iterator.
</description>
		<content:encoded><![CDATA[<p>If you look in java.util.Collections (the utility class), there&#8217;s a set of constants where it switches over algorithms between index-based and iterator-based for non-RandomAccess lists. It&#8217;s interesting to see how large some of those numbers are, particularly with the low cost of memory allocation for the iterator.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
