Code example for LinkedHashSet

Methods: add, remove

0
	} 
	 
	public boolean get (Key key)
	{ 
		if (LOG) log ("searching cache for key " + key);
		if (set.remove (key)) {
			set.add (key); // Move the key to the fresh end
			return true; 
		} 
		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