Question about java Collections

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve High

    Question about java Collections

    Hi.
    I never worked with java's built-in collections framework, and I'm
    having a bit of trouble with it.
    I'm trying to pass a simple char data type into a
    java.util.Linke dList, and I continue to get an incompatible type
    exception (because it's expecting type Object). Is there a way I can
    cast the char or set up the list so I can avoid this? I really dont
    want to write a LinkedList class if one already exists.

    BTW, I'm using the NetBeans IDE from the Sun website, if that means
    anything.

    Thanks.
  • Joe

    #2
    Re: Question about java Collections

    In article <52ce07a1.03092 61154.1bd12274@ posting.google. com>,
    schigh@comcast. net says...
    [color=blue]
    > I'm trying to pass a simple char data type into a
    > java.util.Linke dList, and I continue to get an incompatible type
    > exception (because it's expecting type Object).[/color]


    Use the Character class in the java.lang package to wrap the char
    prinmitive data before adding it the the Collection

    Comment

    • Mitch Williams

      #3
      Re: Question about java Collections

      Joe wrote:
      [color=blue]
      > In article <52ce07a1.03092 61154.1bd12274@ posting.google. com>,
      > schigh@comcast. net says...
      >
      >[color=green]
      >>I'm trying to pass a simple char data type into a
      >>java.util.Lin kedList, and I continue to get an incompatible type
      >>exception (because it's expecting type Object).[/color]
      >
      >
      >
      > Use the Character class in the java.lang package to wrap the char
      > prinmitive data before adding it the the Collection[/color]

      You should also note that when you retrieve your data from the linked,
      it will come in the form of a generic Object. You need to cast it back
      to Character in order to extract your data from it.

      Comment

      • Badhri

        #4
        Re: Question about java Collections

        Mitch Williams <codewarrior123 @cox.net> wrote in message news:<L0Ldb.766 7$Rd4.2521@fed1 read07>...[color=blue]
        > Joe wrote:
        >[color=green]
        > > In article <52ce07a1.03092 61154.1bd12274@ posting.google. com>,
        > > schigh@comcast. net says...
        > >
        > >[color=darkred]
        > >>I'm trying to pass a simple char data type into a
        > >>java.util.Lin kedList, and I continue to get an incompatible type
        > >>exception (because it's expecting type Object).[/color]
        > >
        > >
        > >
        > > Use the Character class in the java.lang package to wrap the char
        > > prinmitive data before adding it the the Collection[/color]
        >
        > You should also note that when you retrieve your data from the linked,
        > it will come in the form of a generic Object. You need to cast it back
        > to Character in order to extract your data from it.[/color]

        Nice thing is that with autoboxing facility to be introduced in JDK1.5
        such painfully redundant syntax are eliminated.

        Comment

        Working...