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 4 of 4

Thread: Count occurrence of a string in an array list

  1. #1
    Junior Member
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Count occurrence of a string in an array list

    How to count occurrence of a string in a string array list. I have 800,000 strings in string list..


  2. #2
    Member Ganeprog's Avatar
    Join Date
    Jan 2014
    Location
    Chennai,India
    Posts
    80
    My Mood
    Love
    Thanks
    3
    Thanked 6 Times in 6 Posts

    Default re: Count occurrence of a string in an array list

    Hi,

    Post your full code what you tried.

    Happy to help you

    thanks,

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

    Default re: Count occurrence of a string in an array list

    Now I have one array of strings which has 60,000 unique strings. I also have one string abcd which has comma separated values of substrings. I want to find the occurrences of those unique strings in string abcd.

    I have tried like this..


    public void getscore () throws FileNotFoundException, IOException{

    byte[] buffer = new byte[1028];
    BufferedInputStream bufferedInput = new BufferedInputStream(new FileInputStream("F:/Major Project/DataSets/Bibsonomy/2008/modified/modified/titledata3"));

    int bytesRead = 0;
    while ((bytesRead = bufferedInput.read(buffer)) != -1) {

    String chunk = new String(buffer, 0, bytesRead);
    String a2[] = chunk.split(",");
    for(int i=0;i<a2.length;i++)
    abc.add(a2[i]);

    String chunk2 = new String(buffer,0,bytesRead);
    String a3[] = chunk.split(",");
    for(int i=0;i<a3.length;i++){
    xyz.add(a3[i]);
    }
    }

    }

    public void findcount (){

    //abc.toArray(a5);
    int n1;
    int c = 0;
    int i =0;
    n1 = abc.size();
    // System.out.println(n1);
    String abcd = abc.toString();
    xyz.toArray(a4);

    findStr = a4[1];
    System.out.println(a4[1]);

    while(!abcd.isEmpty()){
    if(a4[1].equalsIgnoreCase(abcd));
    {
    c++;
    }
    // i++;
    }
    System.out.println("Count is " +c);

    }


    // Thanks for reply..

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default re: Count occurrence of a string in an array list

    Welcome to the forum. Please read this topic to learn how to post code correctly.

    Please give your threads more useful/meaningful titles.

Similar Threads

  1. Convert List<Set<String>> to string array
    By shatlav in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 4th, 2013, 08:16 AM
  2. Using a Loop and Nested Ifs to Count Number of Vowels in a String
    By Potat in forum Loops & Control Statements
    Replies: 17
    Last Post: February 21st, 2013, 09:35 PM
  3. The count for each value in array
    By samar in forum Loops & Control Statements
    Replies: 4
    Last Post: January 4th, 2013, 02:38 PM
  4. [SOLVED] Sorting an object array using string variables from a string array
    By Shadud in forum What's Wrong With My Code?
    Replies: 0
    Last Post: November 26th, 2012, 05:50 PM
  5. Finding the count of a letter in a String?
    By vlkn448 in forum Algorithms & Recursion
    Replies: 7
    Last Post: July 15th, 2012, 11:55 AM