<?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>Pakzilla &#187; Interview Questions</title>
	<atom:link href="http://www.pakzilla.com/tag/interview-questions/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.pakzilla.com</link>
	<description>A blog on Programming, Web and Technology</description>
	<lastBuildDate>Sat, 04 Feb 2012 22:25:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>HashMap vs Hashtable vs HashSet</title>
		<link>http://www.pakzilla.com/2009/08/24/hashmap-vs-hashtable-vs-hashset/</link>
		<comments>http://www.pakzilla.com/2009/08/24/hashmap-vs-hashtable-vs-hashset/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 17:21:35 +0000</pubDate>
		<dc:creator>Tahir Akram</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[Porgramming]]></category>

		<guid isPermaLink="false">http://www.pakzilla.com/?p=564</guid>
		<description><![CDATA[I was reading about collection framework of Java. And was studying Hashtable, HashMap and HashSet. Its quite interesting to know the differences between them. In this post I will discuss these three with examples. Hashtable Hashtable is basically a datastructure to retain values of key-value pair. It didn&#8217;t allow null for both key and value. [...]
Related posts:<ol>
<li><a href='http://www.pakzilla.com/2011/11/03/calling-posterous-api-in-java/' rel='bookmark' title='Calling Posterous API in Java'>Calling Posterous API in Java</a></li>
<li><a href='http://www.pakzilla.com/2010/07/16/fetch-twitter-friends-or-followers-through-rest-api-in-java/' rel='bookmark' title='Fetch Twitter friends or followers through REST API in Java'>Fetch Twitter friends or followers through REST API in Java</a></li>
<li><a href='http://www.pakzilla.com/2009/12/13/tutorial-jpa-on-google-app-engine/' rel='bookmark' title='Tutorial: JPA on Google App Engine'>Tutorial: JPA on Google App Engine</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I was reading about collection framework of Java. And was studying Hashtable, HashMap and HashSet. Its quite interesting to know the differences between them. In this post I will discuss these three with examples.</p>
<p><strong>Hashtable</strong></p>
<p>Hashtable is basically a datastructure to retain values of key-value pair.</p>
<ul>
<li>It didn&#8217;t allow null for both key and value. You will get NullPointerException if you add null value.</li>
<li>It is synchronized. So it comes with its cost. Only one thread can access in one time</li>
</ul>
<pre class="brush: java; title: ; notranslate">
Hashtable&lt;Integer,String&gt;; cityTable = new Hashtable&lt;Integer,String&gt;();
cityTable.put(1, &quot;Lahore&quot;);
cityTable.put(2, &quot;Karachi&quot;);
cityTable.put(3, null); /* NullPointerEcxeption at runtime*/

System.out.println(cityTable.get(1));
System.out.println(cityTable.get(2));
System.out.println(cityTable.get(3));
</pre>
<p><strong>HashMap</strong></p>
<p>Like Hashtable it also accepts key value pair.</p>
<ul>
<li>It allows null for both key and value</li>
<li>It is unsynchronized. So come up with better performance</li>
</ul>
<pre class="brush: java; title: ; notranslate">
HashMap&lt;Integer,String&gt; productMap = new HashMap&lt;Integer,String&gt;();
productMap.put(1, &quot;Keys&quot;);
productMap.put(2, null);
</pre>
<p><strong>HashSet</strong></p>
<p>HashSet does not allow duplicate values. It provides add method rather put method. You also use its contain method to check whether the object is already available in HashSet. HashSet can be used where you want to maintain a unique list.</p>
<pre class="brush: java; title: ; notranslate">
HashSet&lt;String&gt; stateSet = new HashSet&lt;String&gt;();
stateSet.add (&quot;CA&quot;);
stateSet.add (&quot;WI&quot;);
stateSet.add (&quot;NY&quot;);

if (stateSet.contains(&quot;PB&quot;)) /* if CA, it will not add but shows following message*/
     System.out.println(&quot;Already found&quot;);
else
    stateSet.add(&quot;PB&quot;);
</pre>
<p>Related posts:<ol>
<li><a href='http://www.pakzilla.com/2011/11/03/calling-posterous-api-in-java/' rel='bookmark' title='Calling Posterous API in Java'>Calling Posterous API in Java</a></li>
<li><a href='http://www.pakzilla.com/2010/07/16/fetch-twitter-friends-or-followers-through-rest-api-in-java/' rel='bookmark' title='Fetch Twitter friends or followers through REST API in Java'>Fetch Twitter friends or followers through REST API in Java</a></li>
<li><a href='http://www.pakzilla.com/2009/12/13/tutorial-jpa-on-google-app-engine/' rel='bookmark' title='Tutorial: JPA on Google App Engine'>Tutorial: JPA on Google App Engine</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.pakzilla.com/2009/08/24/hashmap-vs-hashtable-vs-hashset/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
	</channel>
</rss>

