This website includes Education Information like a programming language, job interview question, general knowledge.mathematics

Education log

PageNavi Results No.

Ads

Monday, March 15, 2021

what is hashtable in java

 what is hashtable in java

introduction hashtable in java:

In this Tutorial Today Learn HashTable in java programming well hello internet and welcome to tutorial today we're going to talk about Java hash tables and more specifically I'm going to spend a lot of time on hash function s and how they work I'm going to present them in numerous different ways and show you numerous different code examples to make sure you 100% understand this so let's get into it so what exactly is a hash table a hash table is just a data structure like anything else in this tutorial it's probably better to think of it as an array because I'm going to go through this really slowly and completely build up from the base what it does is it offers very fast both insertion as well as searching however they're limited in size because of like I said before it's based off of an array it can however be resized but of course that is to be avoided and they are very hard to order so how to hash tables and hash functions work together well key values are going to be assigned to elements in a hash table just think array using a hash function and what a hash function helps you do is calculate.


 hashtable in java for the best index an item should go in now of course the index must be small enough so that it stays within the constraints of the array size but also it can't overwrite other data in the hash table a hash functions basic job is to store values in an array with a limited size and it does it in a way that the array doesn't need to be searched through whenever the user decides to go and try to find that information in the hash table so this allows you to enter values in any order and be able to find them using a calculation instead of searching through the array and that is why they are very fast so basically if you have your little guy here and he wants information that was stored in a hash table and he has a very specific non duplicate ID for that information that ID is going to go through a calculation and that calculation is going to provide the exact index for that information then it goes directly to that location in the array or the hash-table and sends the in formation back to the user that is in essence what a hash function and how a hash table functions so let's go and look at some code and of course all of the code.


 in this video is available to link underneath the video so and of course it's free and you should get it because it is very heavily commented all right so we're gonna create our array because that's in essence what we're dealing with here also gonna monitor array size and even though I don't think I'm going to use it in this part of the tutorial I'm also going to store the items in our array then I'm going to create my constructor for this and I just called this hash function because that's really what we're gonna be focusing on and it's we're going to receive a size for our array and then we are going to store that array size of course and we are also going to create our array with that specific size in java programming for hashtable in java.


what is hashtable in java:

This class implements a hash table, which maps keys to values. Any non-null object can be used as a key or as a value. Hashtable is similar to HashMap except it is synchronized.

Why is Hashtable used?

A hash table is a data structure that is used to store keys/value pairs. It uses a hash function to compute an index into an array in which an element will be inserted or searched. ... Under reasonable assumptions, the average time required to search for an element in a hash table is O(1).


example hashtable in java:

import java.util.*;  

class Hashtable1{  

 public static void main(String args[]){  
  Hashtable<Integer,String> hm=new Hashtable<Integer,String>();  
  
  hm.put(100,"Amit");  
  hm.put(102,"Ravi");  
  hm.put(101,"Vijay");  
  hm.put(103,"Rahul");  
  
  for(Map.Entry m:hm.entrySet()){  
   System.out.println(m.getKey()+" "+m.getValue());  
  }  
 }  
}

No comments:

Post a Comment