Anyone for a challenge?

A

Andoni

Hi,

I want a way of sorting a list in Java but I don't want to re-invent the
wheel as there are two sorting mechanisms in Java already.

I am using Java 1.4.1.

I have Hashtable which contains textual labels as keys and ArrayLists as
values.
I have to convert this into a LinkedHashMap which contains the same textual
labels as keys but is ordered by the size of the ArrayLists (more than one
of which may be the same), and now no longer contains the ArrayList but
rather contains the count of their values and the addition of their values
as a comma separated string!

Input:
"exe", [3, 6, 9]
"doc", [4, 2, 4]
"xls", [1, 9]
"txt", [2, 2, 3, 2]

Output:
"txt","4,9"
"exe", "3,18"
"doc", "3,10"
"xls","2,10"

Do I have to write a bubble sort myself or can I leverage something's that's
already there?

Thanks in advance,
Andoni
 
A

Andoni

Done,

Used Arrays.sort() to sort the counts and then went through my sorted list
of counts looking for (and removing) the first one I found that matched.

Not forgetting up update my Iterator each time I removed an element from the
ArrayList!!

Thanks,

Andoni.
 
H

hilz

Not forgetting up update my Iterator each time I removed an element from
the
ArrayList!!

instead, you can remove from the iterator directly, which will automatically
remove from the arraylist as well.

HTH
 
B

Boudewijn Dijkstra

Andrew Thompson said:
Excellent. But please do not change the subject lines of your
posts unless absolutely necessary, as the response ...

.... may thread uncorrectly.
 
A

Andrew Thompson

A

Andoni OConchubhair

Thanks, I'll try that. This is a program that is going to run processing
text files for hours so I every instruction skipped is helpful.

I am going to do a full audit of where the slow bits are once I have
finished.

Andoni.
 
V

vikash

I want to learn java through net give me some site add. and java tutorial.






Andoni said:
Done,

Used Arrays.sort() to sort the counts and then went through my sorted list
of counts looking for (and removing) the first one I found that matched.

Not forgetting up update my Iterator each time I removed an element from the
ArrayList!!

Thanks,

Andoni.

Andoni said:
Hi,

I want a way of sorting a list in Java but I don't want to re-invent the
wheel as there are two sorting mechanisms in Java already.

I am using Java 1.4.1.

I have Hashtable which contains textual labels as keys and ArrayLists as
values.
I have to convert this into a LinkedHashMap which contains the same textual
labels as keys but is ordered by the size of the ArrayLists (more than one
of which may be the same), and now no longer contains the ArrayList but
rather contains the count of their values and the addition of their values
as a comma separated string!

Input:
"exe", [3, 6, 9]
"doc", [4, 2, 4]
"xls", [1, 9]
"txt", [2, 2, 3, 2]

Output:
"txt","4,9"
"exe", "3,18"
"doc", "3,10"
"xls","2,10"

Do I have to write a bubble sort myself or can I leverage something's that's
already there?

Thanks in advance,
Andoni
 
A

Andoni

There is only one way to do this:

Go to this page and download Bruce Eckel's great book in PDF format. It is
free and it is a brilliant guide to the Java language. Including myself he
has probably taught many people to program in java.

http://xoomer.virgilio.it/lucadiod/thinking_in_java.htm

Enjoy,
Andoni.

vikash said:
I want to learn java through net give me some site add. and java tutorial.






"Andoni" <[email protected]> wrote in message
Done,

Used Arrays.sort() to sort the counts and then went through my sorted list
of counts looking for (and removing) the first one I found that matched.

Not forgetting up update my Iterator each time I removed an element from the
ArrayList!!

Thanks,

Andoni.

Andoni said:
Hi,

I want a way of sorting a list in Java but I don't want to re-invent the
wheel as there are two sorting mechanisms in Java already.

I am using Java 1.4.1.

I have Hashtable which contains textual labels as keys and ArrayLists as
values.
I have to convert this into a LinkedHashMap which contains the same textual
labels as keys but is ordered by the size of the ArrayLists (more than one
of which may be the same), and now no longer contains the ArrayList but
rather contains the count of their values and the addition of their values
as a comma separated string!

Input:
"exe", [3, 6, 9]
"doc", [4, 2, 4]
"xls", [1, 9]
"txt", [2, 2, 3, 2]

Output:
"txt","4,9"
"exe", "3,18"
"doc", "3,10"
"xls","2,10"

Do I have to write a bubble sort myself or can I leverage something's that's
already there?

Thanks in advance,
Andoni
 
A

Andoni

Have you seen Google's new groups program? I think you can get to it via:

http://groups-beta.google.com

It has fixed this problem. I even checked this thread and it is all in
place!

Yippee.

I don't like the way they have merged groups with Directory though and they
obviously have ambitions over ICQ as well seeing as you can create your own
public and private groups!

Andoni.
 
A

Andrew Thompson

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,072
Latest member
trafficcone

Latest Threads

Top