Avatar of Duke001
Duke001
Flag for United Kingdom of Great Britain and Northern Ireland asked on

java extract key from map and creating sorted set

Hi experts,

I am a novice in Java and I would like to extract the values of a map and add them into a sorted set.

Map<String, List<String>> xxx

Thanks

Duke001
JavaProgramming

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
CEHJ

Try
SortedSet<List<String>> set = new TreeSet<List<String>>(xxx.values());

Open in new window

Duke001

ASKER
i get the following error message:
Semantic error: java.util.ArrayList cannot be cast to java.lang.Comparable
CEHJ

OK. How are you envisaging the sort is meant to work?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Duke001

ASKER
I would like to create a set in alphabetical order, without duplication.
Thanks
CEHJ

But your values are already Lists of Strings ...
Duke001

ASKER
Please find attached the method used to populate the List<String> value of the map.
thanks
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
CEHJ

Nothing attached...
Duke001

ASKER
very strange ... but please have a look now.
method.txt
CEHJ

You need to post the real code - that would neither work nor even compile
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Duke001

ASKER
please find attached all methods.
Problem2.txt
CEHJ

OK. I suspect you're not quite asking for the right thing. You can't really have a SortedSet of Lists of Strings, since they wouldn't really be orderable. If you think otherwise, please tell me how they are to be ordered.

Are you sure you don't just want to eliminate duplicates from something you've got already?
Duke001

ASKER
This is waht the question says:

"Write a public instance method for EmergencyManager called
allDrivers(), with no argument, that, based on the data available in
qualifiedDrivers, extracts, assembles and returns a collection of a
suitable type that itemizes all of the volunteer drivers in alphabetical
order, without duplication. Note that this method does not need to used
by any other method of EmergencyManager."

Thanks
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
CEHJ

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Duke001

ASKER
error: "cannot find symbol - variable whoDrivesWhat
Duke001

ASKER
Sorry,  but having read the question:

"based on the data available in qualifiedDrivers" ... am wrong to say that the information must be retrieved from the map and not from the whoDrivesWhat?

Thanks
Duke001

ASKER
I have compiled the code with the "String[][] whoDrivesWhat" content  in it and it works but I think that is against the assumption of the question.

Thanks
Your help has saved me hundreds of hours of internet surfing.
fblack61
CEHJ

Well i'm not sure of that. It will certainly give you 'all of the volunteer drivers in alphabetical
order, without duplication'. If that is not what's required, then the method name 'allDrivers' is a bad one
Duke001

ASKER
Ok, I am going to accept your suggestion and let see what happens.
Thanks for your support.

Duke001
CEHJ

:)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.