IntelliJ Java IDE
The moose likes Beginning Java and the fly likes HashMap  Vs   Binary Sort Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "HashMap  Vs   Binary Sort" Watch "HashMap  Vs   Binary Sort" New topic
Author

HashMap Vs Binary Sort

kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1248
What is the difference between HashMap(stores key/value pair) and Binary Sort ?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 14606

kri shan wrote:What is the difference between HashMap(stores key/value pair) and Binary Sort ?


These are two completely unrelated things. One is a collection. The other is a algorithm. And the collection doesn't have any relationship whatsoever with that algorithm.

Henry
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612
One's a data structure, one's a sorting algorithm.

(Oops, thought I hit "Submit.")
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1248
Any direct API methods for binary serach in java or i have to write code for binay search in java ?
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 11642

Have a look at Arrays.binarySearch().


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Rob Spoor
Saloon Keeper

Joined: Oct 27, 2005
Posts: 18365

Which only works if they are sorted. This is a requirement of binary sort itself. Arrays.sort can help you with that.
There are also similar methods in java.util.Collections for Lists.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 8428

You're question is sort of like asking 'what is the difference between a house and a cookie recipe. One IS something, the other is a list of directions on HOW TO ACCOMPLISH something.

a HashMap is a structure with some well defined properties.

a Binary Sort is a way to get a bunch of things sorted - there are dozens of ways you COULD get things sorted, but this one works pretty well in many cases.


Never ascribe to malice that which can be adequately explained by stupidity.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12612


18' tall gingerbread house... sometimes a cookie recipe *is* a house!
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 11642

Wait a minute, first you were talking about binary sort, and then you were asking about binary search.

What are you looking for exactly? A tree sort algorithm? Or do you have a collection that's already sorted, and you want to do a binary search to find an element in the collection?
 
 
subject: HashMap Vs Binary Sort
 
Threads others viewed
Searching a collection -linear
WA #1.....word association
sorting the values using Hsh Map
[Solved] HashMap, Which thing defines the order of elements
Code to sort and remove duplicates in ArrayList and Hashmap
developer file tools