Count the number of elements in an Arraylist

My arraylist has these elements inside it.
[house,tom:, agent,, person,, untidy,jack:, ordered,, tidy,, tiled,roof,tom:, agent,, person,,.....]. The list continues like this.
How can I count the number of elements after each tom upto before each jack and same for all words after jack and upto before tom? [for example in the first case there are 3 words after tom and there are 4 words after jack.]
Thanks

don't collapse your lists together. They represent separate data entities and should be kept separate. Go check your [other thread|http://forums.sun.com/thread.jspa?threadID=5416414&tstart=0].
Edited by: DeltaGeek on Nov 17, 2009 11:07 AM

Similar Messages

  • Count the number of elements in comma seperated list of values

    Hello Friends,
    I have a string with comma seperated list of values say
    String v = 34343,erere,ererere,sdfsdfsdfs,4454,5454,dsfsdfsfsd,fsdfsdfsdfs,dfdsfsdfsdfs,sdsfdsf,ererdsdsd45454,fsdfsdfs
    Want to count how many elements are existing in this string .
    Thanks/Kumar

    Hi, Kumar,
    REGEXP_COUNT, which Hoek used, is handy, but it only works in Oracle 11. Which version of Oracle are you using?
    In any version of Oracle, you can count the commas by seeing how much the string shrinks when you remove them.
    LENGTH (str) + 1 - LENGTH (REPLACE (str, ',')) Can str have multiple commas in a row? What if there's nothing between consecutive commas, or nothing by whitespace? Can str begin or end with a comma? Can str consist of nothing but commas? Depending on your answers, you may have to change things. You might want
    REGEXP_COUNT ( str
                 , '[^,]+'
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say which version of Oracle you're using.
    See the forum FAQ {message:id=9360002}

  • Counting the number of elements on a page

    Does anyone know if there is any way that Illustrator can tell you the number of separate items (closed paths) on a page in Illustrator? (Rather than counting them all manually)? Any advice is appreciated.

    Open the Document Info palette, click on the flyout menu and select Objects. I think that will tell you what you need to know.
    [Edit: oops, you beat me to the draw. Why is the post time so different, though? I didn't see reply #1 when I opened the thread!]

  • How Do I Print the Number of Elements in An Array

    How do I print: "There are ____ number of elements in the array?"

    If you have a String holding a sentence, and if you split on non-empty sequences of whitespace (if the string has newlines in it, you'd probably need to pass the argument that makes \s match newlines, and for that you would probably need to use java.util.regex.Pattern -- see the docs and try some tests), when you'd get an array of Strings that were the non-whitespace parts of the original String. That makes for a reasonably good definition of the words in the sentence, although you could arguably get into some gray areas (does "isn't" count as one or two words? Does a sequence of numbers or punctuation qualify as a word?). In that case, counting the number of elements in the resulting array of String. using .length, would be a reasonable way to get the number of words in that sentence, yes.
    But rather than asking for confirmation on forums, why don't run some tests?
    import java.io.*;
    public class TestWordCount {
      public static void main(String[] argv) {
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          String line;
          while((line = in.readLine()) != null) {
            int count = // your code here, to count the words
            System.out.println("I see " + count + " words.");
        } catch (IOException e) {
          e.printStackTrace();
    }Put your word-counting code in there, then run it from the command line. Type in a sentence. See how many words it thinks it found. Does it match with your expectation, or the examples given (hopefully) with your homework assignment?

  • How to get the number of elements in DB

    Could you tell me how to get the number of elements in DB??
    My code to get the number is below, but I think it is not efficient
    DB->cursor(DB, NULL, &cursorp, 0);
    while ((ret = cursorp->c_get(cursorp, &key, &data, DB_NEXT)) == 0)
    count++;
    --------------------------------------------------------------------------------------------------------------

    Hi,
    The most efficient way to get a count from the database is using the DB->stat API (http://docs.oracle.com/cd/E17076_02/html/api_reference/C/dbstat.html)
    The code will be something like:
            DB *dbp;
            DB_BTREE_STAT *statp;
            int ret;
            /* Print out the number of records in the database. */
            if ((ret = dbp->stat(dbp, NULL, &statp, 0)) != 0) {
                    dbp->err(dbp, ret, "DB->stat");
                    goto err1;
            printf("%s: database contains %lu records\n",
                progname, (u_long)statp->bt_ndata);
            free(statp);The code comes from the example included in the distribution at examples/c/ex_btrec.c
    If the database isn't a btree, you should update to the appropriate statistics structure and field.
    It's worth noting that retrieving the count is never a "cheap" operation. The count is not stored in the database - since doing so introduced a single point of contention that creates a bottle neck.
    Regards,
    Alex Gorrod
    Oracle Berkeley DB

  • Programatically count the number of files in a folder

    Hi Folks
    I need to programatically count the number of files in a given folder and return the value to a Program Unit to be included in further processing.
    Can anyone point me in the right direction. I have looked at UTL_FILE but this does not offer what I want.
    Does anyone know of an obscure package in Oracle that I could use?
    I'm using 9i in a W2K environment.
    Many thanks
    Simon Gadd

    Hi,
    following a java based solution i found somewhere on Tom Kyte's AskTom forum.
    GRANT JAVAUSERPRIV to TESTUSER;
    dbms_java.grant_permission( 'TESTUSER', 'SYS:java.io.FilePermission', 'c:\', 'read' );
    create global temporary table DIR_LIST
    ( filename varchar2(255) )
    on commit delete rows
    create or replace and compile java source named "DirList"
    as
      import java.io.*;
      import java.sql.*;
      public class DirList
        public static void getList(String directory)
                           throws SQLException
          File path = new File( directory );
          String[] list = path.list();
          String element;
          for(int i = 0; i < list.length; i++)
              element = list;
    #sql { INSERT INTO DIR_LIST (FILENAME)
    VALUES (:element) };
    create or replace procedure get_dir_list( p_directory in varchar2 )
    as language java
    name 'DirList.getList( java.lang.String )';
    exec get_dir_list( 'c:\temp' );
    select count(*) from dir_list;

  • Write two functions to find the the number of elements in a linked list?

    I am trying to Write two functions to find the the number of elements in a linked list. One method using recursion and One method using a loop...
    //The linked List class is Represented here.
    public class lp {
    public int first;
    public lp rest;
    public lp(int first1, lp rest1)
    first = first1;
    rest = rest1;
    The program i wrote so far is
    import java.util.*;
    import linklist.lp;
    public class listCount{
    //loop function
    public static void show_list(lp list)
    int counter = 0;
    while(list != null)
    list = list.rest;
    counter++;
    System.out.println ("length computed with a loop:" + counter);
    //recursive function
    public static int recursive_count(lp list)
    if (list.first == null)
    return 0;
    else
    return recursive_count(list.rest) + 1;
    //main method
    public static void main (String args[])
    lp list1 = new lp(1, new lp(2, new lp(3, null)));
    show_list(list1);
    System.out.println("length computed with a recursion:" +
    recursive_count(list1));
    at the if (list.first == null) line i get the error " incomparable types:
    int and <nulltype>" I know this is a beginners error but please
    help...What should I do?

    byte, char, short, int, long, float, double, and boolean are primitives, not objects. They have no members, you cannot call methods on them, and they cannot be set to or compared with null.

  • Determining the number of elements defined in an enum

    Hello,
    I have an enum and I want to determine the number of elements (constants) defined in this enum by source code. I know I can use reflection but I just want to know if there's an easier way.
    Thank you very much.

    Hey JavaWisdom,
    You can use the ordinal method. I made a simple example to demonstrate.
    public class NumberOfEnums {
         public static enum Enumeration {
              item1, item2, item3, item4
         public void count() {
              Enumeration[] values = Enumeration.values();
              int numElems = 0;
              for (Enumeration type : values) {
                   if (type.ordinal() > numElems) {
                        numElems = type.ordinal();
              // Correct 0 indexed numbering
              numElems += 1;
              System.out.println("numElems : " + numElems);
         public static void main(String args[]) {
              NumberOfEnums noe = new NumberOfEnums();
              noe.count();
    }Cheers,
    Cypher

  • Servlet to count the number of occurances of a particular node

    Hi
    I am looking for a servlet which will count the number of a particular node which I have supplied of an XML file.
    Can somebody please help me with this?
    Thankyou

    If you are using Xerces, after you have parsed your XML files using a DOMParser, get the document object from the parser like
    Document document = parser.getDocument();
    And then use the command getElementsByTagName("*"); // for all elements
    it will return the node list object (NodeList) which you can get the count (nodeList.getLength())

  • Is there a way to count the number of times an array moves from positive to negative?

    I have an array of values, and I need to find the number of times that the array changes signs (from positive to negative, or vice versa). In other words from a graphical standpoint, how many times a certain line crosses the x-axis. Counting the number of times the array equals zero does not help however, because the array does not always equal exactly zero when it crosses the axis (ie, the points could move from .1 to -.1).
    Thanks for you help. Feel free to email me at [email protected] I only have lv 5.1.1 so if you attach any files, they cannot be version 6.0.

    Attached is a VI showing the # of Pos and Neg numbers in an array, with 0 considered as non-Pos. It is easily modifiable to other parameters - including using the X-axis value as your compare point versus only Zero.
    This is a modified VI from LV (Separate Array.vi)
    Compare this with your other responses to find the best fit.
    Doug
    Attachments:
    arraysizesposneg.vi ‏40 KB

  • How do I count the number of records returned in the CMIS query

    How do I count the number of records returned in the query CMIS?
    SELECT COUNT(*) FROM ora:t:IDC:GlobalProfile WHERE ora:p:xRegionDefinition = \'RD_PROJETOS_EXCLUSIVOS\''}
    Euler Homero

    Hi Euler,
    interestingly enough, the reference guide for CMIS ( http://wiki.alfresco.com/wiki/CMIS_Query_Language ) that I found does not mention the COUNT function at all. On the other hand it states that: "The SELECT clause identifies which virtual columns to return in the result set. It can be either a comma-separated list of one or more queryNames of properties that are defined by queryable object types or * for all virtual columns."
    There are, however, some other posts like e.g. http://alfrescoshare.wordpress.com/2010/01/20/count-the-total-number-of-documents-in-alfresco-using-sql/ which state that they could make it working.
    Having asked in the WebCenter Portal forum, I assume that your content repository is WebCenter Content. The CMIS doc for the Content is available here: http://docs.oracle.com/cd/E23943_01/doc.1111/e15813.pdf (no COUNT there either). It does, however, mention explicitly that "CMIS queries return a Result Set where each Entry object will contain only the properties that were specified in the query.". This means your could rather investigate the Result Set. Note that there are also other means than CMIS how to get the requested result set (e.g. calling a search service directly via so-called RIDC).
    In the given context I am also interested what your use case is. OOTB CMIS in WebCenter Portal is used, for instance, in Content Presenter, where it is content rather than "parameters" what's displayed.

  • How to count the number of rows in a cube!!??

    Experts,
    I can somebody tell me how do I count the number of rows in my cube when i am using listcube???..
    Thanks
    Ashwin

    Hi,
    have a look ath this theard too
    Number of Records in Cube
    regards

  • How to count the number of rows in a resultser object?

    hi there
    how to count the number of rows in a resultser object which may contains millions of rows? besides using a while loop? thanks

    You don't, you execute a query whose result is the record count of those records that match the search and then you execute the actual query to create your record set. Typically you do
    select count(id) from YourTable where [filter]
    from the resulting ResultSet do
    int res.getInt(1);
    which gives you the count and then
    select id from YourTable where [filter]
    to produce the actual result set.
    in the second query the id part can be substituted with the actual fields you want.

  • How to get the number of elements in a tilelist

    I'm writing test cases for a flex application using FlexSelenium and I need to get the number of elements displayed in the tilelist.
    I know that that the tilelist is fed by an array. but i can't access that array from my test case.
    Can anyone tell me how I can get the number of elements in a tilelist on the application? which property of the tilelist can provide that number?

    try tileList.dataProvider.length;

  • How to Count the number of TAB chars value '0A' in a line?

    I have a requirement to count the number of TABs in a text file that I am processing (they must equal 75) to ensure that all the fields have been submitted on the file I am reading?
    How do I identify the TABs in a line?
    I have this so far:
             CONCATENATE gv_unix_file gv_lstfiles-name INTO gv_unix_file.
              OPEN DATASET gv_unix_file for INPUT IN TEXT MODE ENCODING NON-UNICODE.
              IF sy-subrc <> 0 .
                message e000(zz) with 'Cannot access in_uk files'.
              ENDIF.
              CONCATENATE gv_unix_file_arc gv_lstfiles-name INTO gv_unix_file_arc.
              OPEN DATASET gv_unix_file_arc FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
              IF sy-subrc <> 0 .
                message e000(zz) with 'Cannot access in_uk files'.
              ENDIF.
              DO.
                READ DATASET gv_unix_file into lv_str.
                IF sy-subrc <> 0.
                  exit. "exit do loop, file is done.
                else.
                  TRANSFER lv_str to gv_unix_file_arc.
                ENDIF.
              ENDDO.

    Here is a sample code:
    DATA: lv_string TYPE string,
          lv_tab TYPE c VALUE cl_abap_char_utilities=>horizontal_tab,
          lv_i TYPE i.
    DATA: result_tab TYPE match_result_tab.
    DO 3 TIMES.
      CONCATENATE 'A' lv_string INTO lv_string SEPARATED BY lv_tab.
    ENDDO.
    " this is how you need to find how many tabs are in your transfer work area...
    FIND ALL OCCURRENCES OF lv_tab IN lv_string RESULTS result_tab.
    DESCRIBE TABLE result_tab LINES lv_i.
    WRITE:'No. of tabs found:', lv_i.

Maybe you are looking for