public class RecentlyUsedList - Jfokus
public class RecentlyUsedList - Jfokus
public class RecentlyUsedList - Jfokus
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
<strong>public</strong> <strong>class</strong> <strong>RecentlyUsedList</strong><br />
{<br />
<strong>public</strong> void add(String newItem)<br />
{<br />
if(list == null)<br />
list = new ArrayList();<br />
else<br />
list.remove(newItem);<br />
list.add(newItem);<br />
}<br />
<strong>public</strong> int size()<br />
{<br />
return list == null ? 0 : list.size();<br />
}<br />
<strong>public</strong> String get(int index)<br />
{<br />
if(list == null)<br />
throw new IndexOutOfBoundsException();<br />
return list.get(size() – index - 1);<br />
}<br />
private List list;<br />
}<br />
Accidental<br />
complexity from<br />
unnecessary<br />
laziness