[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Win a copy of Flex 4 in Action this week in the Flex forum!
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
Author

HashMap Vs Binary Sort

kri shan
Ranch Hand

Joined: Apr 08, 2004
Messages: 1018

What is the difference between HashMap(stores key/value pair) and Binary Sort ?
Henry Wong
author
Bartender

Joined: Sep 28, 2004
Messages: 9971

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
Bartender

Joined: Sep 29, 2008
Messages: 6740

One's a data structure, one's a sorting algorithm.

(Oops, thought I hit "Submit.")

Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
kri shan
Ranch Hand

Joined: Apr 08, 2004
Messages: 1018

Any direct API methods for binary serach in java or i have to write code for binay search in java ?
Jesper Young
Java Cowboy
Bartender

Joined: Aug 16, 2005
Messages: 7843

Have a look at Arrays.binarySearch().

Java Beginners FAQ - JavaRanch SCJP FAQ
The Java Tutorial - Java SE 6.0 API documentation
Rob Prime
Bartender

Joined: Oct 27, 2005
Messages: 8771

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
Messages: 5728

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.
David Newton
Author
Bartender

Joined: Sep 29, 2008
Messages: 6740



18' tall gingerbread house... sometimes a cookie recipe *is* a house!

This message was edited 1 time. Last update was at by David Newton


Consultant/Trainer | Polyglottal Developer | Struts Committer/PMC | Struts 2 Web Application Development
Jesper Young
Java Cowboy
Bartender

Joined: Aug 16, 2005
Messages: 7843

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?

This message was edited 1 time. Last update was at by Jesper Young


Java Beginners FAQ - JavaRanch SCJP FAQ
The Java Tutorial - Java SE 6.0 API documentation
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
Money Mgt Calculator