<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>406 Not Acceptable &#187; arraylists</title>
	<atom:link href="http://406notacceptable.com/tag/arraylists/feed/" rel="self" type="application/rss+xml" />
	<link>http://406notacceptable.com</link>
	<description>406 Not Acceptable, not just an error message, but now a blog!</description>
	<lastBuildDate>Tue, 28 Jun 2011 15:13:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>ArrayList in J2ME and generics</title>
		<link>http://406notacceptable.com/java/j2me/arraylist-in-j2me-and-generics/</link>
		<comments>http://406notacceptable.com/java/j2me/arraylist-in-j2me-and-generics/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 10:09:33 +0000</pubDate>
		<dc:creator>Jim</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[j2me]]></category>
		<category><![CDATA[arraylists]]></category>
		<category><![CDATA[j2me code]]></category>
		<category><![CDATA[j2me performance]]></category>
		<category><![CDATA[J2ME Polish]]></category>
		<category><![CDATA[NaStar]]></category>

		<guid isPermaLink="false">http://www.406notacceptable.com/?p=130</guid>
		<description><![CDATA[As you may, or may not know, J2ME does not support the ArrayList functionality of standard Java. In addition, as J2ME is based on Java 1.3 it does not feature generics. This means as a developer you are stuck with a choice of using arrays or vectors. Now arrays are fast, but you are stuck [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>As you may, or may not know, J2ME does not support the ArrayList functionality of standard Java. In addition, as J2ME is based on Java 1.3 it does not feature generics. This means as a developer you are stuck with a choice of using arrays or vectors. Now arrays are fast, but you are stuck with the initial size and a number of other issues. These are things you really do not want to be messing around with, unless speed is of the highest priority.</p>
<p>Whilst Vectors are dynamic, they bring about one annoying issue &#8211; you have to cast each entry back from an Object type to its original type on retrieval. This takes up a lot of processor cycles, and on phones processor cycles are a limited commodity. Secondly, you will have to use the Vector enumerator to iterate through your vectors. This is very processor intensive, in NaStar I found this was using around 30% of my cycles! Finally Vectors are synchronised, this means they are thread safe. Now a synchronised collection is much slower than an unsynchonised one; plus, you will most likely not need the safety benefits synchronisation brings. As you will usually be using one thread for acessing your collections in a game (in the main game loop.)</p>
<p>Now the J2ME Polish project gives you the chance to use some Java 1.5 features, most importantly generics are included. Second, an arraylist implementation is included, which uses generics. However, many people have had issues with integrating this plugin to their chosen IDE. I have worked out some <a title="J2ME Polish Netbeans Integration" href="http://www.406notacceptable.com/j2me/fixing-j2me-polish-integration-with-netbeans-6/" target="_self">fixes for Netbeans J2ME Polish integration</a>, but when coding my project decided against using the tools.</p>
<p>So you now find yourself stuck between no generics, slow vectors, or fixing (and maintaining) a plugin.</p>
<p>If all you want is access to ArrayLists or generics, your best bet is to strip the ArrayList code from J2ME Polish and create your own lists. I guess you could simply find an implementation of ArrayList floating around on the web, but the J2ME Polish code is very good. You will then simply create a number of new ArrayList classes, such as SpriteList, EnemyList, et al. There will be two other classes that the ArrayList depends on, you should also clone these for each implementation; these will let you use for each loops! Let each list only deal with one defined type. Now you will no longer have to deal with Vectors and their iterators and will find your game runs a lot faster! I found around 20 &#8211; 60% of processor time was dealing with Iterators; whilst ArrayLists cut this down to under 10%. For my project this was the best performance tweak available.</p>
<p>Before anyone asks, no you can&#8217;t play my game! Sadly the rights are held by the University of Birmingham <img src='http://406notacceptable.com/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' />  Whilst I doubt they care much about a J2Me game!</p>


<p>No related posts.</p><hr />
<p><small>&copy; jim for <a href="http://406notacceptable.com">406 Not Acceptable</a>, 2010. |
<a href="http://406notacceptable.com/java/j2me/arraylist-in-j2me-and-generics/">Permalink</a> |
<a href="http://406notacceptable.com/java/j2me/arraylist-in-j2me-and-generics/#comments">No comment</a> |
Add to
<a href="http://del.icio.us/post?url=http://406notacceptable.com/java/j2me/arraylist-in-j2me-and-generics/&amp;title=ArrayList in J2ME and generics">del.icio.us</a>
<br/>
Post tags: <a href="http://406notacceptable.com/tag/arraylists/" rel="tag">arraylists</a>, <a href="http://406notacceptable.com/tag/j2me-code/" rel="tag">j2me code</a>, <a href="http://406notacceptable.com/tag/j2me-performance/" rel="tag">j2me performance</a>, <a href="http://406notacceptable.com/tag/j2me-polish/" rel="tag">J2ME Polish</a>, <a href="http://406notacceptable.com/tag/nastar/" rel="tag">NaStar</a><br/>
</small></p>
<p><small>Feed enhanced by <a href='http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/'>Better Feed</a> from  <a href='http://planetozh.com/blog/'>Ozh</a></small></p>
]]></content:encoded>
			<wfw:commentRss>http://406notacceptable.com/java/j2me/arraylist-in-j2me-and-generics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

