18.11.2014 Views

public class RecentlyUsedList - Jfokus

public class RecentlyUsedList - Jfokus

public class RecentlyUsedList - Jfokus

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

<strong>public</strong> <strong>class</strong> <strong>RecentlyUsedList</strong><br />

{<br />

<strong>public</strong> boolean isEmpty()<br />

{<br />

return list.isEmpty();<br />

}<br />

<strong>public</strong> int size()<br />

{<br />

return list.size();<br />

}<br />

<strong>public</strong> void add(String newItem)<br />

{<br />

list.remove(newItem);<br />

list.add(0, newItem);<br />

}<br />

<strong>public</strong> void clear()<br />

{<br />

list.clear();<br />

}<br />

private List list = new ArrayList();<br />

}<br />

<strong>RecentlyUsedList</strong> list = new <strong>RecentlyUsedList</strong>();<br />

list.add("Hello, World!");<br />

assert list.size() == 1;<br />

list.clear();<br />

assert list.isEmpty();

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!