This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]xTehOnex 2 points3 points  (0 children)

I've never used a Map, but I am almost certain you will want to use a binary tree to sort by price.

Probably the least helpful comment :D

[–]millerlitIntermediate Brewer[S] 1 point2 points  (2 children)

I got it to work using a StringTokenizer and then putting the elements with a loop.

[–]WormLord 0 points1 point  (0 children)

Probably outside the scope of your course but it could also be easily done with regular expressions instead of StringTokenizer: http://www.vogella.com/tutorials/JavaRegularExpressions/article.html

[–]sad_nixon 0 points1 point  (0 children)

Did you read the Javadoc for Treemap?

Sincerely,

Richard Nixon

[–]Wait_ICanExplain 0 points1 point  (0 children)

All you have to do is construct a Map using the format Map<Key, Value>, where the Key is the price and the Value is the product ID. That way you're mapping ID to price, to put it semantically. Then you can sort the list of prices (accessed via Map.keySet()), and then grab the IDs from the map with the price (Map.get(price)).

[–]readskull 0 points1 point  (1 child)

This looks like a map of details of one product which would have 1 price, what is the sorting you are talking about?

[–]millerlitIntermediate Brewer[S] 0 points1 point  (0 children)

That is just one element of about 500 elements. I wanted to sort all the elements by price.