http://kickjava.com/219.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html lang="en">  <head>    <TITLE> Java  >  Java SE, EE, ME  >  java  >  util  > LinkedList _ Java API By Example, From Geeks To Geeks.</TITLE>    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">    <META name="description" content=" Java  >  Java SE, EE, ME  >  java  >  util  > LinkedList">    <META name="keywords" content="Free Books,Free book,Free Computer Books,Free Computer Book,Free Tech Books,Free Tech Book, j2ee, j2ee example, j2se, j2se example, j2me, j2me example, java, java example, java api, java api example, java jobs, free java books, Free Java Downloads, free java book, java development,enterprise java, java developer,java news,java,resources,jsp,servlets,tomcat,ejb,java and xml,jdo,jdbc,sqlj,jax,jaxp,jaxm,jaxb,jax-rpc,apache,jakarta,open source,wireless java,java 2 micro edition,struts,turbine,velocity,p2p java,jxta,jini,javaspaces,waba,java phone,i-mode,palm,java media,jvm,java 2 standard edition,c#,c sharp,jboss,java book excerpts,java api map, Java   Java SE, EE, ME   java   util  LinkedList">    <link rel="stylesheet" type="text/css" href="/cmn/stylesheet.css" />    <link rel="stylesheet" type="text/css" href="/cmn/kickjava.css" />    <script type="text/javascript" src="/cmn/kickjava.js"></script>    <script type="text/javascript" src="/cmn/kickjava1.js"></script>  </head>  <body lang="en" onload="doBodyOnLoad();">     <script type="text/javascript">doBodyBegin();</script>     <noscript>     <BR/>      Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.     <BR/>     </noscript>    <div id="pageWrapper">      <table id="masthead">        <tr>          <td id="mastheadLeft" >            <A href="http://KickJava.com" target="_top"><img src="/cmn/kickjava.gif" alt="KickJava"></a>&nbsp;&nbsp;&nbsp;Java <acronym title="Application Programming Interface">API</acronym> By Example, From Geeks To Geeks.          </td>          <td id="mastheadRight">            <!-- Google CSE Search Box Begins -->            <form id="searchbox_016019849777797803616:sbkqcucs8tc" action="http://KickJava.com/cmn/googlesearch.html">              <input type="hidden" name="cx" value="016019849777797803616:sbkqcucs8tc" />              <input name="q" type="text" size="20" />                    <input type="image" src="/cmn/go.gif"  name="sa"  border="0" alt="Search Now">              <input type="hidden" name="cof" value="FORID:9" />            </form>            <script type="text/javascript" src="http://www.google.com/coop/cse/brand?form=searchbox_016019849777797803616%3Asbkqcucs8tc"></script>            <!-- Google CSE Search Box Ends -->          </td>        </tr>      </table>      <div id="PageHeading" class="inside">        <h1><A HREF="/">Java</A> > <A HREF="/examples">Java SE, EE, ME</A> > <a href="examples/java.index.htm">java</a> > <a href="examples/java.util.index.htm">util</a> > LinkedList</h1>        <script type="text/javascript">doPageHeading();</script>      </div>      <table id="Top1">        <tr>          <td id="Top11"><script type="text/javascript">doTop11();</script></td>          <td id="Top12"><script type="text/javascript">doTop12();</script></td>        </tr>      </table>      <table id="Top2">        <tr>          <td id="Top21"><script type="text/javascript">doTop21();</script></td>          <td id="Top22"><script type="text/javascript">doTop22();</script></td>        </tr>      </table>      <table id="outerColumnContainer">        <tr id="innerColumnContainer">          <td id="contentColumn">            <div id="contentHeading1" class="inside">              <!--contentHeading1-->            </div>            <div id="contentColumn1" class="inside">              <!--contentColumn1-->              <script type="text/javascript">doContentColumn1();</script>            </div>            <div id="contentHeading2" class="inside">              <!--contentHeading2-->            </div>            <div id="contentColumn2" class="inside">              <script type="text/javascript">var kjClass='java/util/LinkedList';</script><H2>
<FONT SIZE="-1">
<a HREF="examples/java.index.htm">java</a>.<a HREF="examples/java.util.index.htm">util</a></FONT>
<BR>
Class <A HREF="browse.html?219.htm" target=_top>LinkedList</A>&lt;E&gt;</H2>
<PRE>
<A HREF="1241.htm" title="class in java.lang">java.lang.Object</A>
  <IMG SRC="cmn/inherit.gif" ALT="extended by "><A HREF="27.htm" title="class in java.util">java.util.AbstractCollection</A>&lt;E&gt;
      <IMG SRC="cmn/inherit.gif" ALT="extended by "><A HREF="34.htm" title="class in java.util">java.util.AbstractList</A>&lt;E&gt;
          <IMG SRC="cmn/inherit.gif" ALT="extended by "><A HREF="38.htm" title="class in java.util">java.util.AbstractSequentialList</A>&lt;E&gt;
              <IMG SRC="cmn/inherit.gif" ALT="extended by "><B>java.util.LinkedList&lt;E&gt;</B>
</PRE>

<DL>
<DT><B>All Implemented Interfaces:</B> <DD><A HREF="4196.htm" title="interface in java.io">Serializable</A>, <A HREF="4128.htm" title="interface in java.lang">Cloneable</A>, <A HREF="4115.htm" title="interface in java.lang">Iterable</A>&lt;E&gt;, <A HREF="239.htm" title="interface in java.util">Collection</A>&lt;E&gt;, <A HREF="221.htm" title="interface in java.util">List</A>&lt;E&gt;, <A HREF="3764.htm" title="interface in java.util">Queue</A>&lt;E&gt;</DD>
</DL>
<DL>
<DT><B>See Also:</B><DD><A HREF="tops/t219.htm">Top Examples</A>, <A HREF="src/java/util/LinkedList.java.htm" title="java.util.LinkedList source code">Source Code</A>,   
<A HREF="220.htm" title="class in java.util"><CODE>ArrayList</CODE></A>, 
<A HREF="222.htm" title="class in java.util"><CODE>Vector</CODE></A>, 
<A HREF="778.htm#10544"><CODE>Collections.synchronizedList(List)</CODE></A> 
</DL>
</DL>
<HR><A NAME="35330" ID="35330"></A>
<PRE>
public boolean <B>add</B>(<A HREF="219.htm" title="type parameter in LinkedList">E</A>&nbsp;o)</PRE><DL><DT><B>See Also:</B></DT><DD> <A HREF="34.htm" title="class in java.util">AbstractList</A>,  <A HREF="221.htm" title="interface in java.util">List</A>,  <A HREF="239.htm" title="interface in java.util">Collection</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'add(E)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(35330, 'S', 'add(E)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'add');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="35331" ID="35331"></A>
<PRE>
public void <B>add</B>(int&nbsp;index,
                <A HREF="219.htm" title="type parameter in LinkedList">E</A>&nbsp;element)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="2800.htm" title="class in java.lang">IndexOutOfBoundsException</A>,  <A HREF="38.htm" title="class in java.util">AbstractSequentialList</A>,  <A HREF="221.htm" title="interface in java.util">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'add(int, E)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(35331, 'S', 'add(int, E)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'add');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="361" ID="361"></A>
<PRE>
public void <B>add</B>(int&nbsp;index,
                <A HREF="1241.htm">Object</A>&nbsp;element)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="2800.htm">IndexOutOfBoundsException</A>, <A HREF="38.htm">AbstractSequentialList</A>, <A HREF="221.htm">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'add(int, java.lang.Object)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(361, 'S', 'add(int, java.lang.Object)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'add');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[562]<B>Place elements anywhere in the current list</B><BR>By <I>KansasT</I> on 2004/11/29 07:44:25&nbsp;&nbsp;<A HREF=# onclick="return rateCode(361,562, 'S', 'add(int, java.lang.Object)', kjClass);">Rate</A><BR></SMALL><CODE>The add with an index allows you to place elements anywhere in the current list, as the example will show.&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT ID="Public">public</FONT>&nbsp;<FONT ID="Static">static</FONT>&nbsp;<FONT ID="Void">void</FONT>&nbsp;main&nbsp;(&nbsp;String&nbsp;[&nbsp;&nbsp;]&nbsp;&nbsp;args&nbsp;)&nbsp;&nbsp;<FONT ID="Throws">throws</FONT>&nbsp;Exception&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add&nbsp;(&nbsp;"Hello"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add&nbsp;(&nbsp;"world"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add&nbsp;(&nbsp;0,"there"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add&nbsp;(&nbsp;0,"there1"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add&nbsp;(&nbsp;1,"here"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListIterator itt = list.listIterator&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT ID="While">while</FONT>&nbsp;&nbsp;(&nbsp;itt.hasNext&nbsp;(&nbsp;&nbsp;)&nbsp;&nbsp;)&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String line =&nbsp;&nbsp;(&nbsp;String&nbsp;)&nbsp;&nbsp;itt.next&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println&nbsp;(&nbsp;line&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;// end main&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;The output of <FONT ID="This">this</FONT>&nbsp;is:&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;there1&nbsp;<br />&nbsp;here&nbsp;<br />&nbsp;there&nbsp;<br />&nbsp;Hello&nbsp;<br />&nbsp;world&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;since to start with we have:&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;-&nbsp;&gt;&nbsp;"Hello"-&nbsp;&gt;&nbsp;"world"-&nbsp;&gt;&nbsp;end&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1        2&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;After the add&nbsp;(&nbsp;0,"there"&nbsp;)&nbsp;&nbsp;&nbsp;<br />&nbsp;we have&nbsp;<br />&nbsp;-&nbsp;&gt;&nbsp;"there"-&nbsp;&gt;&nbsp;"Hello"-&nbsp;&gt;&nbsp;"world"-&nbsp;&gt;&nbsp;end&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1        2        3&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;And after add&nbsp;(&nbsp;0,"there1"&nbsp;)&nbsp;&nbsp;we have&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;-&nbsp;&gt;&nbsp;"there1"-&nbsp;&gt;&nbsp;"there"-&nbsp;&gt;&nbsp;"Hello"-&nbsp;&gt;&nbsp;"world"-&nbsp;&gt;&nbsp;end&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1        2        3         4&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;therefore when you <FONT ID="Do">do</FONT>&nbsp;the add&nbsp;(&nbsp;1,"here"&nbsp;)&nbsp;&nbsp;<br />&nbsp;you get:&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;-&nbsp;&gt;&nbsp;"there1"-&nbsp;&gt;&nbsp;"here"-&nbsp;&gt;&nbsp;"there"-&nbsp;&gt;&nbsp;"Hello"-&nbsp;&gt;&nbsp;"World"-&nbsp;&gt;&nbsp;end&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1        2       3        4        5&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;because it will insert "here" after element 1 which is now "there1".</FONT></CODE><BR><BR><SMALL>[1864]<B>LinkedList with runtime input</B><BR>By <I>Mubin Ahmed</I> on 2007/02/02 09:18:36&nbsp;&nbsp;<A HREF=# onclick="return rateCode(361,1864, 'S', 'add(int, java.lang.Object)', kjClass);">Rate</A><BR></SMALL><CODE><FONT ID="Import">import</FONT>&nbsp;java.util.Scanner;&nbsp;<br />&nbsp;<FONT ID="Import">import</FONT>&nbsp;java.util.*;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;<FONT ID="Public">public</FONT>&nbsp;<FONT ID="Class">class</FONT>&nbsp;LinkedListUtil&nbsp;{&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT ID="Public">public</FONT>&nbsp;<FONT ID="Static">static</FONT>&nbsp;<FONT ID="Void">void</FONT>&nbsp;main&nbsp;(&nbsp;String args&nbsp;[&nbsp;&nbsp;]&nbsp;&nbsp;)&nbsp;&nbsp;{&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Scanner in=<FONT ID="New">new</FONT>&nbsp;Scanner&nbsp;(&nbsp;System.in&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;LinkedList list=<FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT ID="While">while</FONT>&nbsp;&nbsp;(&nbsp;in.hasNext&nbsp;(&nbsp;&nbsp;)&nbsp;&nbsp;)&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String word = in.next&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;list.add&nbsp;(&nbsp;word&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ListIterator itt = list.listIterator&nbsp;&nbsp;(&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT ID="While">while</FONT>&nbsp;&nbsp;&nbsp;(&nbsp;&nbsp;itt.hasNext&nbsp;&nbsp;(&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String line =&nbsp;&nbsp;&nbsp;(&nbsp;&nbsp;String&nbsp;&nbsp;)&nbsp;&nbsp;&nbsp;itt.next&nbsp;&nbsp;(&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println&nbsp;&nbsp;(&nbsp;&nbsp;line&nbsp;&nbsp;)&nbsp;&nbsp;;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println&nbsp;(&nbsp;"\nList in reverse order........."&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<FONT ID="While">while</FONT>&nbsp;&nbsp;&nbsp;(&nbsp;&nbsp;itt.hasPrevious&nbsp;&nbsp;(&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;String line =&nbsp;&nbsp;&nbsp;(&nbsp;&nbsp;String&nbsp;&nbsp;)&nbsp;&nbsp;&nbsp;itt.previous&nbsp;&nbsp;(&nbsp;&nbsp;&nbsp;&nbsp;)&nbsp;&nbsp;;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println&nbsp;&nbsp;(&nbsp;&nbsp;line&nbsp;&nbsp;)&nbsp;&nbsp;;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;<br />&nbsp;&nbsp;}&nbsp;</FONT></CODE><BR><HR><A NAME="389" ID="389"></A>
<PRE>
public boolean <B>add</B>(<A HREF="1241.htm">Object</A>&nbsp;o)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="34.htm">AbstractList</A>, <A HREF="221.htm">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'add(java.lang.Object)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(389, 'S', 'add(java.lang.Object)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'add');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[940]<B>LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 17:52:07&nbsp;&nbsp;<A HREF=# onclick="return rateCode(389,940, 'S', 'add(java.lang.Object)', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i1 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i2 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2</FONT></CODE><BR><HR><A NAME="476" ID="476"></A>
<PRE>
public boolean <B>addAll</B>(int&nbsp;index,
                      <A HREF="239.htm" title="interface in java.util">Collection</A>&lt;? extends <A HREF="219.htm" title="type parameter in LinkedList">E</A>&gt;&nbsp;c)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="1249.htm" title="class in java.lang">NullPointerException</A>, <A HREF="2800.htm" title="class in java.lang">IndexOutOfBoundsException</A>,  <A HREF="38.htm" title="class in java.util">AbstractSequentialList</A>,  <A HREF="221.htm" title="interface in java.util">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'addAll(int, java.util.Collection)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(476, 'S', 'addAll(int, java.util.Collection)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'addAll');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[941]<B>Nested LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 17:55:55&nbsp;&nbsp;<A HREF=# onclick="return rateCode(476,941, 'S', 'addAll(int, java.util.Collection)', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list1 = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;LinkedList list2 = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i1 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i2 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i3 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list1.add&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list1.add&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list1.add&nbsp;(&nbsp;i3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"And"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"A"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"Haircut"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"Two"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"Bits"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now we list1 that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2-&nbsp;&gt;&nbsp;3&nbsp;<br />&nbsp;//And list2 looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;2, list1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now list2 looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;&nbsp;[&nbsp;&nbsp;1-&nbsp;&gt;&nbsp;2-&nbsp;&gt;&nbsp;3&nbsp;&nbsp;]&nbsp;-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"</FONT></CODE><BR><HR><A NAME="468" ID="468"></A>
<PRE>
public boolean <B>addAll</B>(<A HREF="239.htm" title="interface in java.util">Collection</A>&lt;? extends <A HREF="219.htm" title="type parameter in LinkedList">E</A>&gt;&nbsp;c)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="27.htm#35314"><CODE>AbstractCollection.add(Object)</CODE></A>, <A HREF="1249.htm" title="class in java.lang">NullPointerException</A>,    <A HREF="221.htm" title="interface in java.util">List</A>   </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'addAll(java.util.Collection)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(468, 'S', 'addAll(java.util.Collection)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'addAll');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[942]<B>_</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 17:57:34&nbsp;&nbsp;<A HREF=# onclick="return rateCode(468,942, 'S', 'addAll(java.util.Collection)', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list1 = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;LinkedList list2 = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i1 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i2 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list1.add&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list1.add&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list1.add&nbsp;(&nbsp;i3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"And"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"A"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"Haircut"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"Two"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;"Bits"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now we list1 that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2-&nbsp;&gt;&nbsp;3&nbsp;<br />&nbsp;//And list2 looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;list2.add&nbsp;(&nbsp;list1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now list2 looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"-&nbsp;&gt;&nbsp;&nbsp;[&nbsp;&nbsp;1-&nbsp;&gt;&nbsp;2-&nbsp;&gt;&nbsp;3&nbsp;&nbsp;]&nbsp;</FONT></CODE><BR><HR><A NAME="35384" ID="35384"></A>
<PRE>
public void <B>addFirst</B>(<A HREF="219.htm" title="type parameter in LinkedList">E</A>&nbsp;o)</PRE><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'addFirst(E)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(35384, 'S', 'addFirst(E)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'addFirst');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="43673" ID="43673"></A>
<PRE>
public void <B>addFirst</B>(<A HREF="1241.htm">Object</A>&nbsp;o)</PRE><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'addFirst(java.lang.Object)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(43673, 'S', 'addFirst(java.lang.Object)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'addFirst');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="35390" ID="35390"></A>
<PRE>
public void <B>addLast</B>(<A HREF="219.htm" title="type parameter in LinkedList">E</A>&nbsp;o)</PRE><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'addLast(E)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(35390, 'S', 'addLast(E)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'addLast');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="43674" ID="43674"></A>
<PRE>
public void <B>addLast</B>(<A HREF="1241.htm">Object</A>&nbsp;o)</PRE><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'addLast(java.lang.Object)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(43674, 'S', 'addLast(java.lang.Object)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'addLast');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="15335" ID="15335"></A>
<PRE>
public void <B>clear</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="219.htm" title="type parameter in LinkedList">E</A>, <A HREF="34.htm" title="class in java.util">AbstractList</A>,  <A HREF="221.htm" title="interface in java.util">List</A>,  <A HREF="239.htm" title="interface in java.util">Collection</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'clear()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(15335, 'S', 'clear()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'clear');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[943]<B>Clear LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 18:00:04&nbsp;&nbsp;<A HREF=# onclick="return rateCode(15335,943, 'S', 'clear()', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i1 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i2 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i3 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list1.add&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list1.add&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list1.add&nbsp;(&nbsp;i3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now we list1 that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2-&nbsp;&gt;&nbsp;3&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;list.clear&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now the list is empty&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;<FONT ID="Int">int</FONT>&nbsp;i = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //i = 0</FONT></CODE><BR><HR><A NAME="15484" ID="15484"></A>
<PRE>
public <A HREF="1241.htm" title="class in java.lang">Object</A> <B>clone</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="4128.htm" title="interface in java.lang"><CODE>Cloneable</CODE></A>  </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'clone()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(15484, 'S', 'clone()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'clone');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="16119" ID="16119"></A>
<PRE>
public boolean <B>contains</B>(<A HREF="1241.htm" title="class in java.lang">Object</A>&nbsp;o)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="219.htm" title="type parameter in LinkedList">E</A>, <A HREF="27.htm" title="class in java.util">AbstractCollection</A>,  <A HREF="221.htm" title="interface in java.util">List</A>,  <A HREF="239.htm" title="interface in java.util">Collection</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'contains(java.lang.Object)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(16119, 'S', 'contains(java.lang.Object)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'contains');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[944]<B>Check to see if an item in a LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2005/07/20 14:40:47&nbsp;&nbsp;<A HREF=# onclick="return rateCode(16119,944, 'S', 'contains(java.lang.Object)', kjClass);">Rate</A><BR></SMALL><CODE>ist.add&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"And"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"A"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Haircut"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Two"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Bits"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now list looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;<FONT ID="Boolean">boolean</FONT>&nbsp;b = list.contains&nbsp;(&nbsp;"Haircut"&nbsp;)&nbsp;; //b = true</FONT></CODE><BR><HR><A NAME="39334" ID="39334"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>element</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="1217.htm" title="class in java.util">NoSuchElementException</A>,  <A HREF="3764.htm" title="interface in java.util">Queue</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'element()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(39334, 'S', 'element()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'element');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="20176" ID="20176"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>get</B>(int&nbsp;index)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="2800.htm" title="class in java.lang">IndexOutOfBoundsException</A>,  <A HREF="38.htm" title="class in java.util">AbstractSequentialList</A>,  <A HREF="221.htm" title="interface in java.util">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'get(int)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(20176, 'S', 'get(int)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'get');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[945]<B>Retrieve item from LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 18:05:46&nbsp;&nbsp;<A HREF=# onclick="return rateCode(20176,945, 'S', 'get(int)', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"And"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"A"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Haircut"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Two"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Bits"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now list looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;String s1 =&nbsp;&nbsp;(&nbsp;String&nbsp;)&nbsp;&nbsp;list.get&nbsp;(&nbsp;1&nbsp;)&nbsp;; //s1 = "And"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;String s2 =&nbsp;&nbsp;(&nbsp;String&nbsp;)&nbsp;&nbsp;list.get&nbsp;(&nbsp;3&nbsp;)&nbsp;; //s1 = "Haircut"</FONT></CODE><BR><BR><SMALL>[1307]<B>_</B><BR>By <I>pillepop2003 at yahoo { dot } de</I> on 2005/02/16 14:04:24&nbsp;&nbsp;<A HREF=# onclick="return rateCode(20176,1307, 'S', 'get(int)', kjClass);">Rate</A><BR></SMALL><CODE>Don't forget to&nbsp;&nbsp;(&nbsp;typecast&nbsp;)&nbsp;&nbsp;the Object returned bet get&nbsp;(&nbsp;<FONT ID="Int">int</FONT>&nbsp;)&nbsp;-&nbsp;&nbsp;<br />&nbsp;as I'm quite a newbie to java, it costed me 4958839 hours to find out.&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;bigup 2 kickjava&nbsp;<br />&nbsp;</FONT></CODE><BR><BR><SMALL>[1683]<B></B><BR>By <I>Anonymous</I> on 2005/12/01 20:58:34&nbsp;&nbsp;<A HREF=# onclick="return rateCode(20176,1683, 'S', 'get(int)', kjClass);">Rate</A><BR></SMALL><CODE>Thank you. I'm a newbie too & <FONT ID="This">this</FONT>&nbsp;helped me a<FONT ID="Void">void</FONT>&nbsp;<FONT ID="This">this</FONT>&nbsp;pitfall. </FONT></CODE><BR><HR><A NAME="22968" ID="22968"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>getFirst</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="1217.htm" title="class in java.util">NoSuchElementException</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'getFirst()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(22968, 'S', 'getFirst()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'getFirst');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[946]<B>Retrieve first item from LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 18:07:06&nbsp;&nbsp;<A HREF=# onclick="return rateCode(22968,946, 'S', 'getFirst()', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"And"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"A"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Haircut"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Two"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Bits"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now list looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;String s1 =&nbsp;&nbsp;(&nbsp;String&nbsp;)&nbsp;&nbsp;list.getFirst&nbsp;(&nbsp;&nbsp;)&nbsp;; //s1 = "Shave"</FONT></CODE><BR><HR><A NAME="23839" ID="23839"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>getLast</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="1217.htm" title="class in java.util">NoSuchElementException</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'getLast()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(23839, 'S', 'getLast()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'getLast');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[947]<B>Retrieve last item from LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 18:07:42&nbsp;&nbsp;<A HREF=# onclick="return rateCode(23839,947, 'S', 'getLast()', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"And"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"A"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Haircut"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Two"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Bits"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now list looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;String s1 =&nbsp;&nbsp;(&nbsp;String&nbsp;)&nbsp;&nbsp;list.getLast&nbsp;(&nbsp;&nbsp;)&nbsp;; //s1 = "Bits"&nbsp;<br />&nbsp;</FONT></CODE><BR><HR><A NAME="28839" ID="28839"></A>
<PRE>
public int <B>indexOf</B>(<A HREF="1241.htm" title="class in java.lang">Object</A>&nbsp;o)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="219.htm" title="type parameter in LinkedList">E</A>, <A HREF="34.htm" title="class in java.util">AbstractList</A>,  <A HREF="221.htm" title="interface in java.util">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'indexOf(java.lang.Object)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(28839, 'S', 'indexOf(java.lang.Object)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'indexOf');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[948]<B>Check the position of an item in a LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 19:15:09&nbsp;&nbsp;<A HREF=# onclick="return rateCode(28839,948, 'S', 'indexOf(java.lang.Object)', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;<FONT ID="Int">int</FONT>&nbsp;position;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"And"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"A"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Haircut"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Two"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Bits"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now list looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;position = list.indexOf&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;; //position = 0&nbsp;<br />&nbsp;position = list.indexOf&nbsp;(&nbsp;"Two"&nbsp;)&nbsp;; //position = 4&nbsp;<br />&nbsp;</FONT></CODE><BR><HR><A NAME="1850" ID="1850"></A>
<PRE>
public int <B>lastIndexOf</B>(<A HREF="1241.htm" title="class in java.lang">Object</A>&nbsp;o)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="219.htm" title="type parameter in LinkedList">E</A>, <A HREF="34.htm" title="class in java.util">AbstractList</A>,  <A HREF="221.htm" title="interface in java.util">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'lastIndexOf(java.lang.Object)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(1850, 'S', 'lastIndexOf(java.lang.Object)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'lastIndexOf');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[949]<B>Check the last position of an item in a LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 19:19:18&nbsp;&nbsp;<A HREF=# onclick="return rateCode(1850,949, 'S', 'lastIndexOf(java.lang.Object)', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"And"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"A"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Haircut"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Two"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Bits"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now list looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;position = list.LastIndexOf&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;; //position = 0&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now list looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"Shave"-&nbsp;&gt;&nbsp;"And"-&nbsp;&gt;&nbsp;"A"-&nbsp;&gt;&nbsp;"Haircut"-&nbsp;&gt;&nbsp;"Two"-&nbsp;&gt;&nbsp;"Bits"-&nbsp;&gt;&nbsp;"Shave"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;position = list.LastIndexOf&nbsp;(&nbsp;"Shave"&nbsp;)&nbsp;; //position = 6&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;</FONT></CODE><BR><HR><A NAME="35719" ID="35719"></A>
<PRE>
public <B>LinkedList</B>()</PRE><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'LinkedList()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(35719, 'S', 'LinkedList()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'LinkedList');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="2081" ID="2081"></A>
<PRE>
public <B>LinkedList</B>(<A HREF="239.htm" title="interface in java.util">Collection</A>&lt;? extends <A HREF="219.htm" title="type parameter in LinkedList">E</A>&gt;&nbsp;c)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="1249.htm" title="class in java.lang">NullPointerException</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'LinkedList(java.util.Collection)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(2081, 'S', 'LinkedList(java.util.Collection)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'LinkedList');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[950]<B>Convert a stack to a LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 19:20:18&nbsp;&nbsp;<A HREF=# onclick="return rateCode(2081,950, 'S', 'LinkedList(java.util.Collection)', kjClass);">Rate</A><BR></SMALL><CODE>Stack stack = <FONT ID="New">new</FONT>&nbsp;Stack&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;stack.add&nbsp;(&nbsp;"It"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;stack.add&nbsp;(&nbsp;"was"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;stack.add&nbsp;(&nbsp;"the"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;stack.add&nbsp;(&nbsp;"best"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;stack.add&nbsp;(&nbsp;"of"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;stack.add&nbsp;(&nbsp;"times"&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now we have a collection implemented with a Stack that looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"It"-&nbsp;&gt;&nbsp;"was"-&nbsp;&gt;&nbsp;"the"-&nbsp;&gt;&nbsp;"best"-&nbsp;&gt;&nbsp;"of"-&nbsp;&gt;&nbsp;"times"&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;stack&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//Now we have a LinkedList named list that also looks like&nbsp;<br />&nbsp;//-&nbsp;&gt;&nbsp;"It"-&nbsp;&gt;&nbsp;"was"-&nbsp;&gt;&nbsp;"the"-&nbsp;&gt;&nbsp;"best"-&nbsp;&gt;&nbsp;"of"-&nbsp;&gt;&nbsp;"times"&nbsp;<br />&nbsp;</FONT></CODE><BR><HR><A NAME="2162" ID="2162"></A>
<PRE>
public <A HREF="238.htm" title="interface in java.util">ListIterator</A>&lt;<A HREF="219.htm" title="type parameter in LinkedList">E</A>&gt; <B>listIterator</B>(int&nbsp;index)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="2800.htm" title="class in java.lang">IndexOutOfBoundsException</A>,    <A HREF="221.htm" title="interface in java.util">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'listIterator(int)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(2162, 'S', 'listIterator(int)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'listIterator');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="36265" ID="36265"></A>
<PRE>
public boolean <B>offer</B>(<A HREF="219.htm" title="type parameter in LinkedList">E</A>&nbsp;o)</PRE><DL><DT><B>See Also:</B></DT><DD> <A HREF="3764.htm" title="interface in java.util">Queue</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'offer(E)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(36265, 'S', 'offer(E)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'offer');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="36473" ID="36473"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>peek</B>()</PRE><DL><DT><B>See Also:</B></DT><DD> <A HREF="3764.htm" title="interface in java.util">Queue</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'peek()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(36473, 'S', 'peek()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'peek');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="36519" ID="36519"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>poll</B>()</PRE><DL><DT><B>See Also:</B></DT><DD> <A HREF="3764.htm" title="interface in java.util">Queue</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'poll()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(36519, 'S', 'poll()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'poll');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="36868" ID="36868"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>remove</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="1217.htm" title="class in java.util">NoSuchElementException</A>,  <A HREF="3764.htm" title="interface in java.util">Queue</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'remove()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(36868, 'S', 'remove()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'remove');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="5989" ID="5989"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>remove</B>(int&nbsp;index)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="2800.htm" title="class in java.lang">IndexOutOfBoundsException</A>,  <A HREF="38.htm" title="class in java.util">AbstractSequentialList</A>,  <A HREF="221.htm" title="interface in java.util">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'remove(int)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(5989, 'S', 'remove(int)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'remove');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[835]<B>Number of items in a LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 15:20:10&nbsp;&nbsp;<A HREF=# onclick="return rateCode(5989,835, 'S', 'remove(int)', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList l = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;l.add&nbsp;(&nbsp;<FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;<FONT ID="Int">int</FONT>&nbsp;lSize = l.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 1&nbsp;<br />&nbsp;l.remove&nbsp;(&nbsp;0&nbsp;)&nbsp;;&nbsp;<br />&nbsp;lSize = = l.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 0</FONT></CODE><BR><HR><A NAME="6044" ID="6044"></A>
<PRE>
public boolean <B>remove</B>(<A HREF="1241.htm" title="class in java.lang">Object</A>&nbsp;o)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="219.htm" title="type parameter in LinkedList">E</A>, <A HREF="27.htm" title="class in java.util">AbstractCollection</A>,  <A HREF="221.htm" title="interface in java.util">List</A>,  <A HREF="239.htm" title="interface in java.util">Collection</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'remove(java.lang.Object)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(6044, 'S', 'remove(java.lang.Object)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'remove');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[951]<B>Remove item from LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 20:13:47&nbsp;&nbsp;<A HREF=# onclick="return rateCode(6044,951, 'S', 'remove(java.lang.Object)', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i1 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i2 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2&nbsp;<br />&nbsp;<FONT ID="Int">int</FONT>&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 2&nbsp;<br />&nbsp;Object o = list.remove&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;2&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 1&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;Integer i3 =&nbsp;&nbsp;(&nbsp;Integer&nbsp;)&nbsp;&nbsp;list.remove&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 0</FONT></CODE><BR><HR><A NAME="6235" ID="6235"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>removeFirst</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="1217.htm" title="class in java.util">NoSuchElementException</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'removeFirst()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(6235, 'S', 'removeFirst()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'removeFirst');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[952]<B>Safely remove all the elements in a list</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 20:16:30&nbsp;&nbsp;<A HREF=# onclick="return rateCode(6235,952, 'S', 'removeFirst()', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i1 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i2 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2&nbsp;<br />&nbsp;<FONT ID="Int">int</FONT>&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 2&nbsp;<br />&nbsp;Object o = list.removeFirst&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;2&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 1&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;Integer i3 =&nbsp;&nbsp;(&nbsp;Integer&nbsp;)&nbsp;&nbsp;list.removeFirst&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 0&nbsp;<br />&nbsp;</FONT></CODE><BR><BR><SMALL>[1515]<B>_</B><BR>By <I>ficr { at } hotmail { dot } com</I> on 2005/08/12 09:13:26&nbsp;&nbsp;<A HREF=# onclick="return rateCode(6235,1515, 'S', 'removeFirst()', kjClass);">Rate</A><BR></SMALL><CODE>//Safely remove all the elements in a list&nbsp;<br />&nbsp;<FONT ID="While">while</FONT>&nbsp;&nbsp;(&nbsp;list.size&nbsp;(&nbsp;&nbsp;)&nbsp;&nbsp;!= 0&nbsp;)&nbsp;&nbsp;<br />&nbsp;&nbsp;{&nbsp;&nbsp;<br />&nbsp;&nbsp;System.out.pr<FONT ID="Int">int</FONT>&nbsp;(&nbsp;list.getFirst&nbsp;(&nbsp;&nbsp;)&nbsp;&nbsp;+ " "&nbsp;<br />&nbsp;&nbsp;<FONT ID="Try">try</FONT>&nbsp;{&nbsp;list.removeFirst&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;}&nbsp;&nbsp;<br />&nbsp;&nbsp;<FONT ID="Catch">catch</FONT>&nbsp;(&nbsp;NoSuchElementException e&nbsp;)&nbsp;&nbsp;{&nbsp;<FONT ID="Throw">throw</FONT>&nbsp;<FONT ID="New">new</FONT>&nbsp;RuntimeException&nbsp;(&nbsp;e&nbsp;)&nbsp;;&nbsp;}&nbsp;&nbsp;<br />&nbsp;&nbsp;}&nbsp;</FONT></CODE><BR><HR><A NAME="6290" ID="6290"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>removeLast</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="1217.htm" title="class in java.util">NoSuchElementException</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'removeLast()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(6290, 'S', 'removeLast()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'removeLast');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[953]<B>Remove item from bottom of LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 20:17:32&nbsp;&nbsp;<A HREF=# onclick="return rateCode(6290,953, 'S', 'removeLast()', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i1 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i2 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i3 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2-&nbsp;&gt;&nbsp;3&nbsp;<br />&nbsp;<FONT ID="Int">int</FONT>&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 3&nbsp;<br />&nbsp;Object o = list.removeLast&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 2&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;Integer i4 =&nbsp;&nbsp;(&nbsp;Integer&nbsp;)&nbsp;&nbsp;list.removeLast&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 1&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1&nbsp;<br />&nbsp;</FONT></CODE><BR><HR><A NAME="37215" ID="37215"></A>
<PRE>
public <A HREF="219.htm" title="type parameter in LinkedList">E</A> <B>set</B>(int&nbsp;index,
             <A HREF="219.htm" title="type parameter in LinkedList">E</A>&nbsp;element)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="2800.htm" title="class in java.lang">IndexOutOfBoundsException</A>,  <A HREF="38.htm" title="class in java.util">AbstractSequentialList</A>,  <A HREF="221.htm" title="interface in java.util">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'set(int, E)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(37215, 'S', 'set(int, E)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'set');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="7387" ID="7387"></A>
<PRE>
public <A HREF="1241.htm">Object</A> <B>set</B>(int&nbsp;index,
                  <A HREF="1241.htm">Object</A>&nbsp;element)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="2800.htm">IndexOutOfBoundsException</A>, <A HREF="38.htm">AbstractSequentialList</A>, <A HREF="221.htm">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'set(int, java.lang.Object)', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(7387, 'S', 'set(int, java.lang.Object)', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'set');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[954]<B>Replace items in a LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 20:18:58&nbsp;&nbsp;<A HREF=# onclick="return rateCode(7387,954, 'S', 'set(int, java.lang.Object)', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i1 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i2 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i3 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2-&nbsp;&gt;&nbsp;3&nbsp;<br />&nbsp;<FONT ID="Int">int</FONT>&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 3&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;Integer i4 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;4&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.set&nbsp;(&nbsp;0, i4&nbsp;)&nbsp;;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;4-&nbsp;&gt;&nbsp;2-&nbsp;&gt;&nbsp;3&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;Integer i5 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;5&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i6 = list.set&nbsp;(&nbsp;1, i5&nbsp;)&nbsp;;&nbsp;<br />&nbsp;<FONT ID="Int">int</FONT>&nbsp;i = i6.intValue&nbsp;(&nbsp;&nbsp;)&nbsp;; //i = 2&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;4-&nbsp;&gt;&nbsp;5-&nbsp;&gt;&nbsp;3&nbsp;<br />&nbsp;</FONT></CODE><BR><HR><A NAME="9866" ID="9866"></A>
<PRE>
public int <B>size</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="219.htm" title="type parameter in LinkedList">E</A>, <A HREF="27.htm" title="class in java.util">AbstractCollection</A>,  <A HREF="221.htm" title="interface in java.util">List</A>,  <A HREF="239.htm" title="interface in java.util">Collection</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'size()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(9866, 'S', 'size()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'size');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[955]<B>Add items to a LinkedList</B><BR>By <I>parisjackson { at } yahoo { dot } com</I> on 2004/09/27 20:19:28&nbsp;&nbsp;<A HREF=# onclick="return rateCode(9866,955, 'S', 'size()', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;<br />&nbsp;<FONT ID="Int">int</FONT>&nbsp;lSize;&nbsp;<br />&nbsp;Integer i1 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i2 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;Integer i3 = <FONT ID="New">new</FONT>&nbsp;Integer&nbsp;(&nbsp;3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i1&nbsp;)&nbsp;;&nbsp;<br />&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 1&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i2&nbsp;)&nbsp;;&nbsp;<br />&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 2&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;i3&nbsp;)&nbsp;;&nbsp;<br />&nbsp;lSize = list.size&nbsp;(&nbsp;&nbsp;)&nbsp;; //lSize = 3&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;//now we have a list that looks like&nbsp;<br />&nbsp;// -&nbsp;&gt;&nbsp;1-&nbsp;&gt;&nbsp;2-&nbsp;&gt;&nbsp;3</FONT></CODE><BR><HR><A NAME="11492" ID="11492"></A>
<PRE>
public <A HREF="1241.htm" title="class in java.lang">Object</A>[] <B>toArray</B>()</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="548.htm#35526"><CODE>Arrays.asList(Object[])</CODE></A>, <A HREF="219.htm" title="type parameter in LinkedList">E</A>, <A HREF="27.htm" title="class in java.util">AbstractCollection</A>,  <A HREF="221.htm" title="interface in java.util">List</A>,  <A HREF="239.htm" title="interface in java.util">Collection</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'toArray()', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(11492, 'S', 'toArray()', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'toArray');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><BR><SMALL>[1023]<B>Convert list to array</B><BR>By <I>shiva { dot } s mailtomeshiva { at } yahoo { dot } com</I> on 2004/10/07 05:57:45&nbsp;&nbsp;<A HREF=# onclick="return rateCode(11492,1023, 'S', 'toArray()', kjClass);">Rate</A><BR></SMALL><CODE>LinkedList list = <FONT ID="New">new</FONT>&nbsp;LinkedList&nbsp;(&nbsp;&nbsp;)&nbsp;;&nbsp;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"shiva"&nbsp;)&nbsp;;&nbsp;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"java"&nbsp;)&nbsp;;&nbsp;&nbsp;<br />&nbsp;list.add&nbsp;(&nbsp;"world"&nbsp;)&nbsp;;&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;String&nbsp;[&nbsp;&nbsp;]&nbsp;&nbsp;&nbsp;str = list.toArray&nbsp;(&nbsp;<FONT ID="New">new</FONT>&nbsp;String&nbsp;[&nbsp;list.size&nbsp;(&nbsp;&nbsp;)&nbsp;&nbsp;]&nbsp;&nbsp;)&nbsp;; </FONT></CODE><BR><HR><A NAME="43730" ID="43730"></A>
<PRE>
public <A HREF="1241.htm">Object</A>[] <B>toArray</B>(<A HREF="1241.htm">Object</A>[]&nbsp;a)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="547.htm">ArrayStoreException</A>, <A HREF="27.htm">AbstractCollection</A>, <A HREF="221.htm">List</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'toArray(java.lang.Object[])', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(43730, 'S', 'toArray(java.lang.Object[])', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'toArray');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR><HR><A NAME="38152" ID="38152"></A>
<PRE>
public &lt;T&gt; T[] <B>toArray</B>(T[]&nbsp;a)</PRE><DL><DT><B>See Also:</B></DT><DD><A HREF="1249.htm" title="class in java.lang">NullPointerException</A>, <A HREF="547.htm" title="class in java.lang">ArrayStoreException</A>, <A HREF="219.htm" title="type parameter in LinkedList">E</A>, <A HREF="27.htm" title="class in java.util">AbstractCollection</A>,  <A HREF="221.htm" title="interface in java.util">List</A>,  <A HREF="239.htm" title="interface in java.util">Collection</A> </DD></DL><DL><DT><B>Geek's Notes:</B></DT><DD><A HREF=# onclick="return javaDoc('S', 'toArray(T[])', kjClass);">Description</A>&nbsp;&nbsp;<A HREF=# onclick="return submitCode(38152, 'S', 'toArray(T[])', kjClass);">Add your codes or notes</A>&nbsp;&nbsp;<A HREF=# onclick="return searchExample('LinkedList', 'toArray');">Search More Java Examples</A>&nbsp;&nbsp;</DD></DL><BR>              <script type="text/javascript">doContentColumn2();</script>            </div>            <div id="contentHeading3" class="inside">              <!--contentHeading3-->            </div>            <div id="contentColumn3" class="inside">              <!--contentColumn3-->              <script type="text/javascript">doContentColumn3();</script>            </div>            <div id="contentHeading4" class="inside">              <!--contentHeading4-->            </div>            <div id="contentColumn4" class="inside">              <!--contentColumn4-->              <script type="text/javascript">doContentColumn4();</script>            </div>            <div id="contentHeading5" class="inside">              <!--contentHeading5-->            </div>            <div id="contentColumn5" class="inside">              <!--contentColumn5-->              <script type="text/javascript">doContentColumn5();</script>            </div>          </td>          <td id="rightColumn">            <div id="rightHeading1" class="inside">              <!--rightHeading1-->            </div>            <div id="rightColumn1" class="inside">              <!--rightColumn1-->              <a href="/browse.html" title="JavaDoc, source codes and sample codes for all the Java SE, EE, and ME methods organized alphabetically in one central place." id="menu1" target="_top">A to Z: JavaDoc & Examples</a>              <hr class="hide">              <a href="/news" title="Daily Java news and articles, updated continuously from 100+ Java news sources." id="menu2" target="_top">Daily Java News & Articles</a>              <hr class="hide">              <a href="/prj" title="Java Open Source Projects by Tags." id="menu3" target="_top">Open Source Projects</a>              <hr class="hide">              <a href="/src" title="34,081,897 lines of Java Open Source Codes." id="menu4" target="_top">Open Source Codes</a>              <hr class="hide">              <a href="/books" title="A large collection of free online computer books." id="menu5" target="_top">Free Computer Books</a>              <hr class="hide">              <a href=# title="Remove Frame." onclick="removeFrame();" id="menu6" target="_top">Remove Frame</a>              <hr class="hide">              <script type="text/javascript">doRightColumn1();</script>            </div>            <div id="rightHeading2" class="inside">              <!--rightHeading2-->            </div>            <div id="rightColumn2" class="inside">              <!--rightColumn2-->              <script type="text/javascript">doRightColumn2();</script>            </div>            <div id="rightHeading3" class="inside">              Popular Tags            </div>            <div id="rightColumn3" class="inside">              <!--rightColumn3-->              <script type="text/javascript">doRightColumn3();</script>            </div>            <div id="rightHeading4" class="inside">              <!--rightHeading4-->            </div>            <div id="rightColumn4" class="inside">              <!--rightColumn4-->              <script type="text/javascript">doRightColumn4();</script>            </div>            <div id="rightHeading5" class="inside">              <!--rightHeading5-->            </div>            <div id="rightColumn5" class="inside">              <!--rightColumn5-->              <script type="text/javascript">doRightColumn5();</script>            </div>          </td>        </tr>      </table>      <table id="Bottom1">        <tr>          <td id="Bottom10"><script type="text/javascript">doBottom10();</script></td>          <td id="Bottom11"><script type="text/javascript">doBottom11();</script></td>          <td id="Bottom12"><script type="text/javascript">doBottom12();</script></td>          <td id="Bottom13"><script type="text/javascript">doBottom13();</script></td>          <td id="Bottom14"><script type="text/javascript">doBottom14();</script></td>          <td id="Bottom15"><script type="text/javascript">doBottom15();</script></td>          <td id="Bottom16"><script type="text/javascript">doBottom16();</script></td>          <td id="Bottom17"><script type="text/javascript">doBottom17();</script></td>          <td id="Bottom18"><script type="text/javascript">doBottom18();</script></td>          <td id="Bottom10"><script type="text/javascript">doBottom19();</script></td>        </tr>      </table>      <table id="Bottom2">        <tr>          <td id="Bottom20"><script type="text/javascript">doBottom20();</script></td>          <td id="Bottom21"><script type="text/javascript">doBottom21();</script></td>          <td id="Bottom22"><script type="text/javascript">doBottom22();</script></td>          <td id="Bottom23"><script type="text/javascript">doBottom23();</script></td>          <td id="Bottom24"><script type="text/javascript">doBottom24();</script></td>          <td id="Bottom25"><script type="text/javascript">doBottom25();</script></td>          <td id="Bottom26"><script type="text/javascript">doBottom26();</script></td>          <td id="Bottom27"><script type="text/javascript">doBottom27();</script></td>          <td id="Bottom28"><script type="text/javascript">doBottom28();</script></td>          <td id="Bottom29"><script type="text/javascript">doBottom29();</script></td>        </tr>      </table>      <div id="footer" class="inside">        <hr class="hide">        <p>          Java <acronym title="Application Programming Interface">API</acronym> By Example, From Geeks To Geeks.&nbsp;|&nbsp;          <A href="http://121space.com/blog/kickjava" target="_top">Our Blog</A>&nbsp;|&nbsp;          <A href="/cmn/condition.html" target="_top">Conditions of Use</A><A href="/sitemap_index.xml"> </a>&nbsp;|&nbsp;          <A href="/cmn/about.html" target="_top">About Us</A><A href="/all.html.gz"> </a>&nbsp;|&nbsp;          <script type="text/javascript">doFooter();</script>        </p>      </div>    </div>    <script type="text/javascript">doBodyEnd();</script>    <script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>    <script type="text/javascript">_uacct = "UA-437240-2";urchinTracker();</script>    <DIV ID="divWindow" NAME="divWindow"></DIV>  </body></html>
