CSC/ECE 517 Fall 2007/wiki1 1 aman: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
'''
'''
'''Comparison of HashMaps in Java vs hashes in Ruby'''
'''HashMaps in Java vs hashes in Ruby'''


'''Map''' : A map is any unordered object which stores associations between keys and their corresponding values, in which both keys and the values are objects. The key is unique , however the values may not necessarily be unique. The key, is used to retrieve a value from the map at a later stage after having had stored the values.
'''Map''' : A map is any unordered object which stores associations between keys and their corresponding values, in which both keys and the values are objects. The key is unique , however the values may not necessarily be unique. The key, is used to retrieve a value from the map at a later stage after having had stored the values.


'''HashMaps in java''' : In java an AbstractMap class may implement the Map Interface, which maps unique keys to values. The HashMap Class extends this AbstractMap and uses a hash table to store the map. Maps in general do not implement the Iterable interface. Hence iterations through a map are not possible using a for loop and also it is not possible to obtain an iterator to a map. To implement the iteration feature , a collection view of the map for example a set needs to be used .
'''HashMaps in java''' : In java an AbstractMap class may implement the Map Interface, which maps unique keys to values. The HashMap Class extends this AbstractMap and uses a hash table to store the map. Maps in general do not implement the Iterable interface. Hence iterations through a map are not possible using a for loop and also it is not possible to obtain an iterator to a map. To implement the iteration feature , a collection view of the map for example a set needs to be used .  


'''Hashes in ruby''' : Similar to java, in ruby hashes also are an unordered collection of key-value pairs , but unlike in java hashes in ruby are implemented the same way as an array. Also since Ruby has the feature of inbuilt iteration, iterating over hashes can be done with the
'''Hashes in ruby''' : Similar to java, in ruby hashes also are an unordered collection of key-value pairs , but unlike in java hashes in ruby are implemented the same way as an array. Also since Ruby has the feature of inbuilt iteration, iterating over hashes can be done with the each, each_value, each_key or each_pair method.
 
'''Comparing Hashmaps and hashes
'''

Revision as of 03:08, 12 September 2007

HashMaps in Java vs hashes in Ruby

Map : A map is any unordered object which stores associations between keys and their corresponding values, in which both keys and the values are objects. The key is unique , however the values may not necessarily be unique. The key, is used to retrieve a value from the map at a later stage after having had stored the values.

HashMaps in java : In java an AbstractMap class may implement the Map Interface, which maps unique keys to values. The HashMap Class extends this AbstractMap and uses a hash table to store the map. Maps in general do not implement the Iterable interface. Hence iterations through a map are not possible using a for loop and also it is not possible to obtain an iterator to a map. To implement the iteration feature , a collection view of the map for example a set needs to be used .

Hashes in ruby : Similar to java, in ruby hashes also are an unordered collection of key-value pairs , but unlike in java hashes in ruby are implemented the same way as an array. Also since Ruby has the feature of inbuilt iteration, iterating over hashes can be done with the each, each_value, each_key or each_pair method.

Comparing Hashmaps and hashes