Code example for LinkedHashSet

Methods: add, iterator, remove, size

0
		return false; 
	} 
	 
	public void put (Key key)
	{ 
		if (set.remove (key)) {
			if (LOG) log ("key " + key + " already in cache");
		} 
		else { 
			if (LOG) log ("adding key " + key + " to cache");
			if (set.size() == capacity) {
				// Discard the oldest element 
				Key oldest = set.iterator().next();
				if (LOG) log ("discarding key " + oldest);
				set.remove (oldest);
			} 
		} 
		set.add (key); // Add or move the key to the fresh end
	} 
	 
	private void log (String message)
	{ 
		Event.log (message);