Can you explain what is the difference between hashtable and hashmap?

0 votes
Hi,

Actually I am confused what should I use for my case hashtable or hashmap?

I need to add null values as a key.

So can you explain which one should be perfect for my code?

Thank you
4 days ago in Java by Priya
19 views

1 answer to this question.

0 votes

Hi,

  1. Hashtable is synchronized, whereas HashMap is not. This makes HashMap better for non-threaded applications, as unsynchronized Objects typically perform better than synchronized ones.

  2. Hashtable does not allow null keys or values. HashMap allows one null key and any number of null values.

  3. One of HashMap's subclasses is LinkedHashMap, so in the event that you'd want a predictable iteration order (which is insertion order by default), you could easily swap out the HashMap for a LinkedHashMap. This wouldn't be as easy if you were using Hashtable.

I hope you clear with your doubt.
Thank you,
answered 4 days ago by anonymous

Related Questions In Java

0 votes
1 answer

What is the difference between Map and HashMap in java?

Hi Sanhati, I understand your doubt regarding map ...READ MORE

answered May 31 in Java by Sampriti
• 1,100 points
81 views
+1 vote
1 answer

Can you please explain the difference between string, string buffer and string builder?

String are immutable where as StringBuffer and ...READ MORE

answered Jul 4 in Java by Akash
• 160 points
55 views
0 votes
2 answers

What is the difference between implements and extends?

Extends : This is used to get attributes ...READ MORE

answered Aug 3, 2018 in Java by samarth295
• 2,190 points
449 views
0 votes
1 answer

What is the difference between jdk and jre?

JRE: It stands for Java Runtime Environment. ...READ MORE

answered Apr 20, 2018 in Java by Akrati
• 3,150 points
116 views
+5 votes
3 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,380 points

edited Nov 6, 2018 by Omkar 7,065 views
0 votes
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,050 points
1,794 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points
4,686 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,050 points
405 views
0 votes
2 answers

What is the difference between string object and string literal?

A String literal is a Java language concept. This ...READ MORE

answered 3 days ago in Java by Sirajul
• 17,000 points
71 views
0 votes
4 answers

What is difference between access modifier and access specifier in java

Access Specifier:- This can be understood as ...READ MORE

answered Feb 14 in Java by Priyaj
• 56,200 points
2,403 views