Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

hash tree in java

/* Java program to print frequencies of all elements using 
   TreeMap */
import java.util.*;

class Main
{
    // This function prints frequencies of all elements
    static void printFreq(int arr[])
    {
        // Creates an empty TreeMap
        TreeMap<Integer, Integer> tmap =
                     new TreeMap<Integer, Integer>();

        // Traverse through the given array
        for (int i = 0; i < arr.length; i++)
        {
            Integer c = tmap.get(arr[i]);

            // If this is first occurrence of element   
            if (tmap.get(arr[i]) == null)
               tmap.put(arr[i], 1);

            // If elements already exists in hash map
            else
              tmap.put(arr[i], ++c);
        }

        // Print result
        for (Map.Entry m:tmap.entrySet())
          System.out.println("Frequency of " + m.getKey() + 
                             " is " + m.getValue());
    }

    // Driver method to test above method
    public static void main (String[] args)
    {
        int arr[] = {10, 34, 5, 10, 3, 5, 10};
        printFreq(arr);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: viewResolver 
Java :: how to validate information against the database in java 
Java :: java format zero padded binary 
Java :: bukkit scheduler self cancelling task 
Java :: string in java 
Java :: setting up javafx in eclipse 
Java :: executors java 
Java :: what is method overriding in java 
Java :: math.round java 
Java :: how to make a for loop increment by 2 in java 
Java :: java lambda 
Java :: java join list 
Java :: java enum from int 
Java :: palindrome in java 
Java :: java compare char 
Java :: log4j2.properties file need to save in spring boot application 
Java :: how to find a int 
Java :: postfix operator in java 
Java :: java gerüst 
Java :: how apache shiro remember me works 
Sql :: mysql disable foreign key checks 
Sql :: select not matching data with join table 
Sql :: remove mysql from centos 7 
Sql :: psql: error: could not connect to server: No such file or directory 
Sql :: oracle list columns 
Sql :: get all tables postgres 
Sql :: mysql database stopped xampp mac 
Sql :: log queries postgre 
Sql :: run postgres with docker 
Sql :: mysql text to decimal 
ADD CONTENT
Topic
Content
Source link
Name
9+3 =