Results 1 to 5 of 5

Thread: Treemaps

  1. #1
    sandraW is offline Member
    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0

    Smile Treemaps

    TreeMap(Integer,Integer> treeMap = new TreeMap<Integer,Integer>();

    What exactly does this line of code do, casting??

  2. #2
    crikey is offline Senior Member
    Join Date
    Jul 2010
    Posts
    125
    Rep Power
    0

    Default

    The object "TreeMap" expects two integers as parameters. I don't have experience with TreeMap's, but with HashMaps, when you insert data into them, you place two integers to abide by the parametrized object.

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

    Default

    Nonsense.
    Or at least a misunderstanding of what a Map is.

    Maps (all Maps) map a Key to a Value. What that code above is doing is declaring treeMap as of type TreeMap<Integer, Integer>, the first being the class of the key and the second being the class of the value. It is also initialising it (the stuff on the right hand side).

    The <..> stuff is all to do with generics.

  4. #4
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    The code above does nothing but give you a compilation error because it is a typo.
    Java Code:
    TreeMap(Integer,Integer> treeMap = new TreeMap<Integer,Integer>();
    should be:
    Java Code:
    TreeMap<Integer,Integer> treeMap = new TreeMap<Integer,Integer>();
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,014
    Rep Power
    20

Similar Threads

  1. TreeMaps
    By DavidG24 in forum New To Java
    Replies: 4
    Last Post: 05-05-2009, 05:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •