Object to int

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • oll3i
    Contributor
    • Mar 2007
    • 679

    #1

    Object to int

    Set aposteriori_key s=mapa.keySet() ;
    Object[] keys_tab=aposte riori_keys.toAr ray();

    i need to convert every keys_tab to int how do i do that?

    thank YOU
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by oll3i
    Set aposteriori_key s=mapa.keySet() ;
    Object[] keys_tab=aposte riori_keys.toAr ray();

    i need to convert every keys_tab to int how do i do that?

    thank YOU
    Type cast to Integer first
    [CODE=java]int y = (Integer)keys_t ab[1];[/CODE]

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      Originally posted by r035198x
      Type cast to Integer first
      [CODE=java]int y = (Integer)keys_t ab[1];[/CODE]
      ... or use generics; you don't need the cast then.

      kind regards,

      Jos

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by JosAH
        ... or use generics; you don't need the cast then.

        kind regards,

        Jos
        Oh yeah, and then they'd use the overloaded toArray(T[] t) method in Set.

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by r035198x
          Oh yeah, and then they'd use the overloaded toArray(T[] t) method in Set.
          Great fun isn't it? That won't work for 'T' equal to 'int'. Pure OOP! ;-)

          Autoboxing is a curse.

          kind regards,

          Jos

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by JosAH
            Great fun isn't it? That won't work for 'T' equal to 'int'. Pure OOP! ;-)

            Autoboxing is a curse.

            kind regards,

            Jos
            Yep, T will have to be Integer.
            Reminds of something I picked up from C# (delegates), alright I'll start a new thread about it.

            Comment

            Working...