473,382 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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.LinkedList, 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.
Jul 17 '05 #1
3 3511
Joe
In article <52**************************@posting.google.com >,
sc****@comcast.net says...
I'm trying to pass a simple char data type into a
java.util.LinkedList, and I continue to get an incompatible type
exception (because it's expecting type Object).

Use the Character class in the java.lang package to wrap the char
prinmitive data before adding it the the Collection
Jul 17 '05 #2
Joe wrote:
In article <52**************************@posting.google.com >,
sc****@comcast.net says...

I'm trying to pass a simple char data type into a
java.util.LinkedList, and I continue to get an incompatible type
exception (because it's expecting type Object).


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


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.

Jul 17 '05 #3
Mitch Williams <co************@cox.net> wrote in message news:<L0Ldb.7667$Rd4.2521@fed1read07>...
Joe wrote:
In article <52**************************@posting.google.com >,
sc****@comcast.net says...

I'm trying to pass a simple char data type into a
java.util.LinkedList, and I continue to get an incompatible type
exception (because it's expecting type Object).


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


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.


Nice thing is that with autoboxing facility to be introduced in JDK1.5
such painfully redundant syntax are eliminated.
Jul 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: mark | last post by:
I've been getting odd compile errors when trying to sort while using generics. I have the following code: static final List<Class> levelList; static { Vector<Class> v = new Vector<Class>();...
8
by: Ray | last post by:
Hello there, I've been programming in Java for about 8 years now, but lately I've been hearing a lot about Python and I'm really interested in learning more about it. I've read the tutorial, and...
25
by: Digital Puer | last post by:
I'm looking at some software development jobs whose listings require C++ experience. My history is that I have a strong C background, and a few years of C++ from undergrad classes. I've been...
4
by: 3rdshiftcoder | last post by:
Hi- I'd like to use this class from a book but am getting a compiler error. On the line private List < String > list; p.932 Chapter 19 found in the code below in the eclipse editor it is...
0
by: daniel li | last post by:
I got another convert issue. This is the same project as I posted yesterday, and received a perfect response. The conversion threw a SupportClass for me and one of the data type is...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
16
by: coosa | last post by:
Dear all, I'm familiar with the Set Class in C++ and Java; however, i have been searching in C# for a similar container as in c++ or collection as in java, but couldn't find one. Could some one...
16
by: 3rdshiftcoder | last post by:
hi- where would someone find things like lists, sets, map classes like a hash map or tree map. not specifically those but in general is there a book section that deals with it? in java you can...
1
by: raagadeepthi | last post by:
Getting below error when iam trying to sort the values: Oct 29 04:33:52 WARN cb.DefaultController - Cannot forward after response has been committed java.lang.IllegalStateException: Cannot...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.