Count number of times a specific element occurs in ArrayList

I need to count the number of times a specific element occurs in an ArrayList. For example, if an ArrayList 'overflow' consists of the following elements:
1,3,4,1,1,8,14,7,3,7,8,0.
I need to count the number of times 4 occurs in the list.
ArrayList overflow = new ArrayList();
if(overflow.contains(4))
}I know that contains returns true if 4 exists in the ArrayList, but how do I count the number of times 4 occurs? Any help will be appreciated. Thank you.

There is the Collections.frequency method in j2se 1.5
Or you could loop through the values in the ArrayList and count the number of times it occurs.

Similar Messages

  • How do I count the number of times a particular year occurs in a range of dates?

    One column in my spreadsheet is a date and time.  I want to be able to count how many times a particular year occurs.
    Is there a way to combine the COUNTIFS and YEAR functions, or is there something easier to use?
    I'm using Numbers '09.
    Thank you for your assistance.

    You could use COUNTIFS with the two conditions being ">="&DATE(year, 1,1) and "<"&DATE(the next year, 1,1)

  • Count number of times each char appears??

    Hi! I'm trying to figure out, how to count the number of times ech character appears in the text using ascii code??

    Go the text character-by-character, and count each character. It's that simple.
    The only remotely hard part is holding your character counters. You could use a Map.
    But if you know that the characters are always going to be ASCII, then there's only going to be 128 of them.
    So an array of int with 128 elements should be sufficient.
    Those are more than enough hints. Go do your homework now.

  • QUERY WHICH COUNTS NUMBER OF TIMES WORDS/LETTER APPEAR IN SENTENCE - Thanks

    I have this query below
    it gives the number of times a txn is hign comfort and Approved
    .. nyumber of times txn is meduim comfort and approved etc.
    There is a futher line whihc shows the number of times txn is blacklisted BL COUNT.
    I am trying to get line of query which can show me the number of times txn is approved, is high comfort and blcklisted ( the same applies for
    wl - watch listed)
    The query i am using
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('BL(%') and cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=High Comfort%')
     THEN 1
    ELSE 0 END)AS hbcl  - NO RESULTS BEING GIVEN
    pLEASE CAN ANYONE HELP,. THANKS
    QUERY
    USE RiskManagementReporting
    GO
    DECLARE
    @StartDate DATETIME,
    @EndDate DATETIME
    SET @StartDate
    = '2014-01-01 00:00:00'
    SET @EndDate
    = '2014-03-31 23:59:59'
    SELECT
    CONVERT
    (VARCHAR(10),
    mt.OPacket_TransactionTime, 102)
    AS [Date],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=High Comfort%')
    THEN 1 ELSE 0
    END) AS [A - HighC],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=Medium Comfort%')
    THEN 1 ELSE 0
    END) AS [A - MediumC],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=Low Comfort%')
    THEN 1 ELSE 0
    END) AS [A - LowC],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Declined%')
    AND cc.Comment
    LIKE ('%ComfortLevel=Low Risk%')
    THEN 1 ELSE 0
    END) AS [D - LowR],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Declined%')
    AND cc.Comment
    LIKE ('%ComfortLevel=Medium Risk%')
    THEN 1 ELSE 0
    END) AS [D - MediumR],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Declined%')
    AND cc.Comment
    LIKE ('%ComfortLevel=High Risk%')
    THEN 1 ELSE 0
    END) AS [D - HighR],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('BL(%')
    THEN 1 ELSE 0
    END) AS [BL Count],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('WL(%')
    THEN 1 ELSE 0
    END) AS [WL Count],
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Marked as Touched%')
    THEN 1 ELSE 0
    END) AS [Touched by DRT],
    COUNT
    (mt.csnTransactionId)
    AS [Sent to DRT]
    FROM MatchedTransaction mt
    WITH (NOLOCK)
    LEFT
    JOIN CustomerComment cc
    WITH (NOLOCK)
    ON (mt.csnTransactionId
    = cc.SenderMTCN
    AND cc.InsertDate
    BETWEEN @StartDate AND
    DATEADD (D, 1, @EndDate)

    I have adjusted this as  
    SUM
    (CASE
    WHEN cc.Comment
    LIKE ('Approved%')
    AND cc.Comment
    LIKE ('%ComfortLevel=High Comfort%')
    AND cc.Comment
    LIKE ('%BL(%')THEN 1
    ELSE 0 END)
    AS hcbl,
    Still no result

  • Count number of times an instructor has taught a class

    Howdy Folks, I'm using a lifeline to see if i can get some help for a question. I apologoze in advance, i know this is a numbers forum, but i am working with an excel spreadsheet and was hopng someone could give me a push in the right direction. i want to count how many times an instructor has taught a class based on dates. The spreadsheet is filled out via an applescript so the instructor's name appears with every student. I've been trying to use the count if formula in excel but i cant make it work. any suggestions? it should count james as 2 since he taught classes on two different dates, and nub as 1. all information is fictional and used for demo pruposes.

    This will work for you... I hope:
    I had to add three columns to your existing table, then crete a second table (on the right) to summarize:
    The three columns can be anywhere but I added then right after column G
    The table on the right in this example will have to be a new sheet in excel.  On a mac Numbers is free (If you have Mavericks) so maybe you want to try to download from the App store.
    H2=IF(COUNTIF( $H$1:H1, F2&"-"&E2)=0, F2&"-"&E2, "")
    this is shorthand for... select cell H2, then type (or copy and paste from here) the formula:
    =IF(COUNTIF( $H$1:H1, F2&"-"&E2)=0, F2&"-"&E2, "")
    I2=IF(H2="", "", MAX($I$1:I1)+1)
    J2=IF(COUNTIF($F$1:F1,F2)>0, "", MAX($J$1:J1)+1)
    select H2 thru J2, copy
    select H2 thru the end of  column J
    paste
    In the new table (for Numbers) or sheet(in excel):
    A2=IF((ROW()−2)<MAX(Table 2::J), OFFSET(Table 2::$F$2,MATCH(ROW()−1, Table 2::J,0), 0),"")
    B2=IF(A2≠"", COUNTIFS(Table 2::F, A2, Table 2::I, ">0"), "")
    select A2 and B2, copy
    fill down as needed

  • How to count number of members on specific level at specific moment?

    ASO
    4 dims(for example)...
    -Times
    -Product
    -Organizations
    -org1
    -org2
    -orgN
    -Measures
    -cost
    -org_num
    I want to identify the count of memebers in Dimension Organizations at any time(f.e. for all Products in January in) . What is the syntax of mdx formula in outline?

    Here is an example that i've right now
    Count (EXCEPT([Dimension1].Levels(0).members,Descendants([Parent 1],Levels([Dimension1],0))))
    This will give all the level 0 members of dimensions except level 0 of a parent.
    I'm assuming that by specific moment you mean a specific measure.
    NonEmptyCount (Market.Levels(0).Members, Sales,exclude_missing)
    With
    Member [Measures].[Number Of Markets]
    as 'NonEmptyCount (Market.Levels(0).Members, Sales,exclude_missing)'
    Select
    {[Measures].[Number Of Markets]} on Columns,
    {[100].Children, [200].Children} on Rows
    FROM Sample.Basic
    where ([jan],[actual])This will give you
    (axis)     Number of Markets
    100-10     20
    100-20     16
    100-30     8
    200-10     20
    200-20     17
    200-30     9
    200-40     3
    Now if you clear one market (I cleared colorado->100-10,Sales,Actual,Jan) and then the result will change to
    (axis)     Number of Markets
    100-10     19
    100-20     16
    100-30     8
    200-10     20
    200-20     17
    200-30     9
    200-40     3
    Regards
    Celvin
    http://www.orahyplabs.com

  • Count Number of Times an App ls Launched/Used

    Anyone know if there's an app and/or API or something that would let you know how many times another application-- or actually all other applications-- were either (a) launched (first time) and (b) brought to the foreground (used more than once)? I did a forum search here and couldn't find any reference, and maybe it's more of a developer question, just thought someone might have heard of an existing app that already does something like it or know if there's an existing API call that would allow it. Thx KV

    James should show 2 classes and nub should show 1 class. sorry

  • Need to count the number of times the Basic Finish data chages

    HI Expertes,
    I have a requirement I need to count number of times the Basic finish date chaged for PM work order. I went throug our forums I got some info like using a standard function module
    CHANGEDOCUMENT_READ_HDRS_ONLY
    CHANGEDOCUMENT_READ_HEADERS
    CHANGEDOCUMENT_READ_POSITIONS
    But all the above function module will not be suitable for my requirement since  CHANGEDOCUMENT_READ_HDRS_ONLY it gives whole changes but my requirement is just need number of changes occurred in Basic Finish date but CHANGEDOCUMENT_READ_POSITIONS can give the filed number which has been changed but still I need change id.
    So kindly suggest me wether there is any other Standard FM to get number of changes occurred in Basic Finish date?
    Thanks,
    Rajesh

    Hi Debbie,
         To count the number of groups please try the folling steps:
    1) Create a formula @reset and place this formula in the page header
        whileprintingrecords;
        numbervar i:=0;
    2) Create another formula @evalgroup place this in the group header where you want to count the values.
        whileprintingrecords;
        numbervar i:= i+1;
    3) Create another formula @display and place this in report footer.
        whileprintingrecords;
        numbervar i;
    In order to display the count of details which are printing in the detail section place the eval formula in the detail section and the @display formula in the group footer.
    Hope this helps!!!
    Regards,
    Vinay

  • Help counting a specific letter in a arrayList

    Hello I have made some code that suppose to count how many times a and e occurs in my arraylist. The problem is that it only works if an element consist of one letter. Could anyone tell me how I can make it work?
    import java.util.*;
    public class ex1
        public static void main(String[] args)
            ArrayList<String> words = new ArrayList<String>();
            words.add("ape");
            words.add("egg");
            words.add("and");
            words.add("e");
            words.add("bald");
            words.add("crap");
            averageVowels(words);
         public static void averageVowels(ArrayList<String> list)
             int count = 0;
                    for (int i = 0; i < list.size(); i++)  //for (String w: list)
                    if (list.get(i).equals("a")|| list.get(i).equals("e"))     
                           count++;
                    System.out.println(count);
    }

    baudits wrote:
    Hello I have made some code that suppose to count how many times a and e occurs in my arraylist. The problem is that it only works if an element consist of one letter. Could anyone tell me how I can make it work? How many times does it "occur" here:
    words.add("a");
    words.add("aa");Two, or three?
    If two, use String.contains("a") instead of .equals(). You're currently comparing each entire entry of your list of Strings to "a" or "e", so clearly only exactly "a" or "e" would increment count.
    If three, you'll need to iterate through each character of each word, not just through each word:
    for ( String word : words ) {
       for ( char c : word.toCharArray() ) {
          if ( c == 'a' ) {
             count++;
          } //etc
    }Edited by: endasil on 26-Nov-2009 2:55 PM

  • Count number of triggered events

    I'm trying to continually retrigger a digital output; is there a way to count the number of times the trigger has occurred? 
    Right now I have it set up where it triggers off the 20MHzTimebase. Would using the counter CI Count Edges on the 20MHzTimebase give a correct reading? Or is there a better/known way to do it?

    CMW.. wrote:
    just one little addition to the vi provided in the previous post from Vij@y,
    I would place the Trigger-Button inside the eventcase of the Trigger.valuechange, so it will reset after it is read out without the toggeling.
    In addition, the count indicator belongs before the event structure so it correctly shows zero if the program is started but no button has been pressed yet. (another option would be to enable "clear indicators when called" on the vi properties...execution page).
    Still, this has nothing to do with the original question.
    LabVIEW Champion . Do more with less code and in less time .

  • Calculate number of times a name appears within a date range.

    Hello,
    I am actually using the iPad version but I assume the formula will be the same. Say I have a date in column A and a list of names in column B. What would the formula be to calculate the number of times a specific name appears in a date range.
    Thank you

    If C2 = the minimum date of the range
    C3= the maximum date of the range
    and you are looking for John as the name
    =COUNTIFS($A,">="&C2,$A,"<="&C3,B,"john")
    which counts cells where A>=the min date and A<=the max date and B="john"

  • Times a specific link is clicked

    how to calculate number of times a specific link is clicked?

    863765 wrote:
    I have a website where i need to calculate how many clicks are coming to my website??I already captured client ip addresses, Plz tell me if u have any solution regarding my requirementIt is interesting that you still have not said -
    1) what server you are running (Tomacat, Apache, JBoss etc etc etc)
    2) what persistent storage you have available (database, file system etc etc)
    3) what server side programming languages you have available (Java, PHP, Perl etc)
    4) where and how you are currently storing the captured IP addresses.
    You really are not helping yourself by drip feeding us the environment.
    Bye

  • Counting number of occurances

    I have an array of queues,
    eg:
    1, 2 ,3
    4, 5 , 6
    1, 8, 9
    2, 4, 5
    so everytime i poll each queue I get the value of the first column. I need to count the occurances of each value. Eg for this example, 1 appear twice, 4 appear once and 2 appear once. How can I do this efficiently since I may have to fetch up to 1000 queue records?
    Thanks.

    Don't ask for much do ya!
    private int occurances[9];
    //the above array holds a value for each number up to the
    //maximum number we are looking for (presumed to be 9).
    //the array will hold an int representing how many times each
    //value has been found in a queue.
    constructor { //rename this so it is a proper constructor.
        for (int i = 0; i < occurances.length; i++) {
             occurances[i] = 0; //initialise all values of the array to zero.
    public void analyseQueue(ArrayList queue[])
        for (int i = 0; i < queue.length; i++) { //for each queue:
            ArrayList currentQ = queue; //extract the queue
    for (int n = 0; n < currentQ.size(); n++) { //for each element in the queue:
    int n = (int) currentQ.get(n); //extract the integer value of the element.
    occurances[n - 1]++; //as this number has been found, increase the
    //number of occurances of it. Note the -1 as an array is zero indexed.
    public int getOccurances(int n) {
    return occurances[n - 1]; //again, because zero indexed.

  • Looping a movie clip a specific number of times in Flash

    Does anyone know how to get a movie clip to loop a specific number of times in Flash? I know how to stop a movie clip from looping by using the this.stop (); command by placing the command in a separate Action Script layer, in a keyframe, inside of the movie clip's timeline. This allows the movie clip to play through once and then stop. But I need for the movie clip to loop more than once, maybe 2 or 3 times, and then go back to the main timeline. Does anyone know the code for this?
    Also, is it possible to place a pause (I'm guessing, maybe by using a timer of some type?) between the loops, so that the movie will pause a couple of seconds before it loops again and then stop? Please note I do not need the movie clip to stop when there's an event like a rollover or anything. I just need it to play a couple of times, pause between plays and then stop and go back to the main timeline. Please let me know if anyone can help.
    Thanks,
    Sarah
    P.S. Is there a good, easy to use, reference book anyone can recommend for creating specific things in Flash using Action Script? Do you guys have a favorite for beginners like me?

    You can use a variable to keep count of how many times you loop, and until it exceeds a particulr value (2 or 3) you execute a setTimeout() call that waits for however long you want to delay and then tells the movieclip to gotoAndPlay(1).
    So in the first frame you would establish the counting variable...
    var count;
    if(count == undefined){ // only set it to 0 once
    count = 0;
    and in the last frame you would do your incrementing and control....
    stop();
    count += 1;
    if(count < 3){
    setTimeout(waitABit, 2000); // call function in 2 secs
    function waitABit(){
    gotoAndPlay(1);

  • ORA-24333: zero iteration count  Cause: An iteration count of zero was specified for the statement Action: Specify the number of times this statement must be executed

    Get the following error from Oracle 
    ORA-24333: zero iteration count
    Cause: An iteration count of zero was specified for the statement
    Action: Specify the number of times this statement must be executed
    Any suggestions on whether is this a Oracle bug or if not what should be set to avoid this failure.

    Hello get this from executing the following.
    Occurs intermitently.
    select MAX(LENGTH(lxVal)) from lxString_74501fb6 where lxType=910231053
    Find the MaxLenght(LxVal) returned is null for this query.
    Did google it but says the iterator not initialized. But not the case here
    Thanks

Maybe you are looking for

  • What Is the best way to upload and download psd files from Photoshop to Photoshop Touch? [was:Re]

    What Is the best way to up load and down load psd files from desktop photo shop to photo shop touch? For on the go touch up or. I'm using psd files at 90 percent 300 depi when in photo shop on desktop. To ps touch

  • No option to export a portal page (9i)

    hello, i have to export some of our portal pages to our new application server 10g (windows 2000/ windows 2003 server). I have two questions concerning to that: 1. If I browse the portal pages in the navigator view there is no 'export' action next to

  • HT1657 having problems renting movies on appleTV

    We are having problems using our appleTV, earlier today it wouldn't show up on my ipad while watching a podast, we had to watch it form the ipad instead of the TV. Then we rented a movie from the iTunes store on the appleTV and it told us it would ta

  • ADF BC 11 - best practice question

    Hi, I think that many developers/architects working with development in the SOA area, are facing the same problem as we have. The SOA architecture promis you decoupled systems that are highly adaptable and flexible. However most systems also have use

  • Control swf from separate swf in main file

    Im loading 2 swfs into my main swf. So I have a top swf and a bottom swf being loaded in externally into my main swf that makes 3 swfs, 1MAIN swf loading TOP swf & BOTTOM swf. Is there a way to have the bottom swf control or command the top swf? I ne