How to create and use Hashtable, ArrayList (really urgent, please)
Hi guys,
I'm new to Java, and little bit confused with arrays. It's easy to do it in PHP, but it is different in Java.
I need to create an array, like the one listed below, and print it using "for" loops. Could you please help me with that. Thanks in advance.
myCatsAndSubcats = array(
"Books" => array(
"Book1", "Book2", "Book3"
),
"Food" => array(
"Food1", "Food2", "Food3"
),
"Medical" => array(
"Pills1", "Pills2", "Pills3"
),
);
I guess I need something like Hashtable<String, ArrayList<String>> myCategories = new Hashtable<String, ArrayList<String>>();
So now I need to add several categories(to be precise, "Books", "Food", "Medical"), and for each particular category I need to add the list of its subcategories.
Do I need to fill categories first, with elements (Book, Food, Medicals), and than use put() method for each one?
categoryMap.put("Book", "Book1");
categoryMap.put("Book", "Book2");
categoryMap.put("Book", "Book3");
categoryMap.put("Food", "Food1");
etc.
How do I actually add elements to categories?
I feel like a dummy in Java.
That's why I just need a working example (an array, mentioned above as well as its printout), so I can review the code, understand what exactly does that code and write my own, with changes.
Tried to find some examples for my particular problem, but no luck.
Thank you!!!
Re: How to create and use Hashtable, ArrayList (really urgent, please)
To the original poster, cross-posting without notifying all threads can frustrate anyone who tries to help you when they find out later that the same answer was given hours ago in a cross-posted thread. No one likes wasting their time, especially a volunteer. The polite thing to do would be that if you feel that you absolutely must cross-post, to at least provide links in both cross-posts to each other.
One link: How to create and use Hashtable, ArrayList (really urgent, please)
Please supply the rest.
Re: How to create and use Hashtable, ArrayList (really urgent, please)
Sorry, my bad.
I thought these forum are two different forums, I needed to find solution asap.
Already solved the problem.
Thank you!
Re: How to create and use Hashtable, ArrayList (really urgent, please)
They *are* two different forums. But that doesn't excuse your possibly making volunteers do busy work for no purpose, by trying to help when the problem has already been solved. I think you know the answer to this. Again, in the future, please notify all if you cross-post.
Re: How to create and use Hashtable, ArrayList (really urgent, please)
Thank you.
In future I will provide a link to the post containing the same question, if any.