Results 1 to 2 of 2

Thread: Using Collection

  1. #1
    Junior Member
    Join Date
    Jun 2007
    Answers
    7

    Using Collection

    Using Collection Please tell me the code for the following

    Hi
    I have some number of strings and I want to calculate number of times a particular String appears.
    eg.
    Suppose I have 10 Strings
    String s1="Ram";
    String s2="Sham";
    String s3="Ram";
    String s4="Sham";
    String s5="Sham";
    String s6="Sham";
    String s7="Ram";
    String s8="Ram";
    String s9="Sham";
    String s10="Ram";

    I want to calculate how many times Ram and Sham appears.

    Please revert me soon


  2. #2
    Contributing Member
    Join Date
    Sep 2006
    Answers
    42

    Re: Using Collection

    Hi Gaurav0252,
    What you can do is to store all these Strings in an Array.
    Loop through the array comparing every element with every other element. You could also declare an integer array where you will store the count.

    Regards,
    Sahil.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact