Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm having a problem using HashMap. I have test.txt with this data:

[Computers]
Keyboard=10
Mouse=5
[Cars]
Lamborghini=6
BMW=3

where the [Computers] & [Cars] are Category, Keyboard, Mouse, Lamborghini and BMW are descriptors, and 10, 5, 6, 3 are values for each descriptor.

How can I make a HashMap that can System.out.println("Category" + "descriptor" + value) on console or in JTextArea when clicking a button?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
223 views
Welcome To Ask or Share your Answers For Others

1 Answer

I think it can be done using two levels of hashmaps.

On first hashmap level, use category as your key and for its value, use another hashmap whose keys would be the descriptors.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...