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: The count for each value in array

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default The count for each value in array

    Can You please help me in this:

    I need to count the number of each value in non fixed array
    for example
    3 times the word 'java' exist
    4 times the word 'programming' exists and etc
    Many Thanks


  2. #2
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    1,069
    Thanks
    7
    Thanked 215 Times in 191 Posts

    Default Re: The count for each value in array

    Use a map from string keys to integer count values. For each item in the array
    (1) If no entry exists in the map for that item, create one with a value of 1
    (2) If an entry does exist increment its value.

    The Map Interface (The Java™ Tutorials > Collections > Interfaces)

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Re: The count for each value in array

    5 minutes of programming and I get this result:
    *** code removed ***
    Last edited by Norm; January 4th, 2013 at 01:57 PM. Reason: spoonfed code removed.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,268
    Thanks
    56
    Thanked 2,372 Times in 2,343 Posts

    Default Re: The count for each value in array

    @icool - Instead of spoonfeeding code to the OP, how about helping him learn how to program so he can write his own code.
    The Problem with Spoon-feeding
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: The count for each value in array

    Ok, I see what you mean

Similar Threads

  1. Character Count Frequently
    By ndundupan in forum What's Wrong With My Code?
    Replies: 3
    Last Post: December 14th, 2011, 09:07 PM
  2. Where I'm I wrong? I need to do a count of the number of each element in an array
    By NavagatingJava in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 21st, 2011, 02:50 AM
  3. How to Count the CAPS
    By Sean137 in forum Java Theory & Questions
    Replies: 1
    Last Post: December 14th, 2010, 08:30 AM
  4. Method to count objects
    By mjpam in forum Java Theory & Questions
    Replies: 5
    Last Post: July 28th, 2010, 09:49 AM
  5. select count(*)
    By jacinto in forum JDBC & Databases
    Replies: 4
    Last Post: March 2nd, 2010, 10:30 PM