Here you can find the source of printTopNTokens(LinkedList
Parameter | Description |
---|---|
list | a parameter |
n | a parameter |
public static void printTopNTokens(LinkedList<Entry<String, Integer>> list, int n)
//package com.java2s; //License from project: Open Source License import java.util.Iterator; import java.util.LinkedList; import java.util.Map.Entry; public class Main { /**// ww w . j a va 2 s . c o m * This function takes a sorted List as input and print top N elements * @param list * @param n */ public static void printTopNTokens(LinkedList<Entry<String, Integer>> list, int n) { Iterator<Entry<String, Integer>> iterator = list.descendingIterator(); int size = list.size() - 1; if (size < 0) { System.out.println("Empty Set"); return; } System.out.format("\n%-20s%20s\n", "Token", "Frequency"); System.out.println("---------------------------------------------------------------------------------"); for (int i = 0; i < n; i++) { System.out.format("\n%-20s%20s", list.get(size - i).getKey(), list.get(size - i).getValue()); } System.out.println(); } }