Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: How to create and use Hashtable, ArrayList (really urgent, please)

  1. #1
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Exclamation 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!!!


  2. #2
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default 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.

  3. #3
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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!

  4. #4
    Super Moderator curmudgeon's Avatar
    Join Date
    Aug 2012
    Posts
    1,130
    My Mood
    Cynical
    Thanks
    64
    Thanked 140 Times in 135 Posts

    Default 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.

  5. #5
    Junior Member
    Join Date
    Nov 2012
    Posts
    3
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default 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.

  6. The Following User Says Thank You to GBPython For This Useful Post:

    curmudgeon (November 6th, 2012)

Similar Threads

  1. [SOLVED] Question about hashtable
    By leonne in forum Java Theory & Questions
    Replies: 3
    Last Post: November 4th, 2012, 12:09 PM
  2. I need help with Enumeration in hashtable
    By jaouharia1 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 2nd, 2012, 08:17 PM
  3. Need urgent help regarding java word wrap function.. URGENT
    By coldice in forum What's Wrong With My Code?
    Replies: 3
    Last Post: August 16th, 2011, 05:43 AM
  4. arraylist, hashtable, and 1~2 dimension arrays
    By Perd1t1on in forum Object Oriented Programming
    Replies: 4
    Last Post: July 25th, 2010, 01:25 PM

Tags for this Thread