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 2: Line 2:
'''Comparison of HashMaps in Java vs hashes in Ruby'''
'''Comparison of HashMaps in Java vs hashes in Ruby'''


'''Map''' : A map is any 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'''
'''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

Revision as of 02:48, 12 September 2007

Comparison of 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