import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

/**
 * {@link <a href=
 * "https://[Log in to view URL]"
 * target= "_blank">Primitive LinkedHashMap<K, V></a>}
 * 
 * @author itammb ( Italia Massimiliano Buscati )
 * @version JDK 1.15
 *
 */
class Main {
	public static enum Game {
		CRICKET, HOCKEY, TENNIS
	}

	public static class UniTestLinkedHashMap {

		/**
		 * @see ArrayList#ArrayList(java.util.Collection)
		 * @see Collections#sort(List, Comparator)
		 * 
		 */
		public void applaySort(Map<Game, Short> buffer) {
			List<Map.Entry<Game, Short>> entries = new ArrayList<Map.Entry<Game, Short>>(buffer.entrySet());

			Collections.sort(entries, new Comparator<Map.Entry<Game, Short>>() {
				public int compare(Map.Entry<Game, Short> a, Map.Entry<Game, Short> b) {
					return a.getValue().compareTo(b.getValue());
				}
			});

			for (int i = 0; i < entries.size(); i++)
				System.out.print("[i=" + i + ", e -> " + entries.get(i) + "] ");

			println();

		}

		/**
		 * @see Map#entrySet()
		 * @see Iterator
		 * 
		 */
		public void applayIterator(Map<Game, Short> buffer) {
			if (buffer.isEmpty())
				System.out.print("[]");
			else
				for (Iterator<Entry<Game, Short>> itr = buffer.entrySet().iterator(); itr.hasNext();)
					System.out.print(itr.next() + " ");

			println();
		}

		private static void println() {
			System.out.println();
		}

		/**
		 * @see Map#ofEntries(Entry...)
		 *
		 */
		public static LinkedHashMap<Game, Short> createTest() {
			Map<Game, Short> source = Map.ofEntries(Map.entry(Game.CRICKET, Short.valueOf("1")),
					Map.entry(Game.HOCKEY, Short.valueOf("2")), Map.entry(Game.TENNIS, Short.valueOf("3")));

			LinkedHashMap<Game, Short> buffer = new LinkedHashMap<Game, Short>(source);

			return buffer;
		}
	}

	public static void main(String args[]) throws Exception {
		// Unit test - ordina una struttura e restituisce una lista
		new UniTestLinkedHashMap().applaySort(UniTestLinkedHashMap.createTest());

		// Unit test - attraversa una struttura con l'ausilio di un'interfaccia
		// Iteretor<E>
		new UniTestLinkedHashMap().applayIterator(UniTestLinkedHashMap.createTest());
	}
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: