Java List Print printTopNTokens(LinkedList> list, int n)

Here you can find the source of printTopNTokens(LinkedList> list, int n)

Description

This function takes a sorted List as input and print top N elements

License

Open Source License

Parameter

Parameter Description
list a parameter
n a parameter

Declaration

public static void printTopNTokens(LinkedList<Entry<String, Integer>> list, int n) 

Method Source Code

//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();

    }
}

Related

  1. printStats(final List shocktimes)
  2. printStringList(List list, String name)
  3. printStringList(List listToPrint)
  4. printStringList(List strings)
  5. printTable(List data)
  6. printTuple(List tuple)
  7. printTwoColumns(List left, List right, int leftWidth, int rightWidth, int sep)
  8. printValues(List values)
  9. printWithBars(int[] maxLength, String[] headings, List rows)

  10. HOME | Copyright © www.java2s.com 2016