Arraylist.toString (need to count amount of a specific character in a list)

hi
I have a sql query that im using to populate a ArrayList<String>. I need to count the amount of "+" symbols in the all of the list. My first idea was to use Arraylist.toString and then run the resulting string through this method
public static int countMsgs(String result){
          int counter = 0;
          for(int i=0;i<result.length();i++)
                    if(result.charAt(i)=='+')
                    counter++;                                      
          return counter;However when I do this:
ResultSet userid1021result = sql.executeQuery
      ("select address from MESSAGES where SENT_TIME >=  '" + start + " 00:00:00' AND SENT_TIME <= '"+ end + " 23:59:59' "
      + "and USER_ID = 1");
      while (userid1021result.next()) {
              String addresses = userid1021result.getString("address");
              userid1021.add(addresses);
      String blah = userid1021result.toString();
      System.out.println(blah);It outputs "com.mysql.jdbc.JDBC4ResultSet@1abc7b9" which is obviously not what i was expecting
How do i get the contents of the arraylist into one big string so I can run it through my countMsgs method?
Thanks

Guys,
Where a, b, and c are strings: plusesIn(a) + plusesIn(b) + plusesIn(c) == plusesIn(a+b+c)
Ergo, concatenating the strings is just a waste of time.
Also... I'd factor out the character-to-find from countMsgs to make a static helper method (in a "reusable" StringUtils class)...
* Returns the number of times target occurs in string
public static final int occurences(String string, char target) {
  int count = 0;
  for ( char c : s.toCharArray() ) { // 1.6 only
    if( c == target ) count++;
  return target;
}

Similar Messages

  • I see people from different ages at my work and every month I need to count how many people from each age I've seen that month. How can I do to give the entries to numbers in a single cell and make numbers count them for me?

    I see people from different ages at my work and every month I need to count how many people from each age I've seen that month. How can I do to give the entries to numbers in a single cell and make numbers count them for me? The final result would be a spreadsheet telling there were 8 people from 20 to 39 years old, 14 peolple from 40 to 59 and so on...

    jpqcampos wrote:
    This appears to be an 'input form' using 'Radio Buttons' to select the category. Neither of these features are supported in Numbers '09.
    You can input the data on one table and summarize it on a second table, but the input table will continue to hold data for each event.
    And by using the Reorganize button, you can hide all but two rows of that table to approximate the appearance and performance of an input form.
    Here are the two tables, Data on the left and Summary on the right. Notes below.
    The grey-filled columns in both tables are 'working' columns, and may be hidden (as shown in the image below).
    Data table:
    D1 contains the word "TRUE" (in capital letters). (This row is always shown.)
    D2 is empty, or may contain any value except "TRUE" (This row is always hidden under the Reorganize rule.)The rest of Row 2 of this table requires the data shown: a number outside the range to be counted (999), and two checkboxes, both checked.
    D3 (and filled down the rest of column D):   =AND(OR(B2,C2),NOT(OR(B3,C3)))
    The formula returns TRUE only for the first unused row in the table (ie. the first row for which neither checkbox has been checked)
    Summary table:
    Column A contains labels for the age ranges to be counted.
    Column B contains the same information in the form necessary for the formulas in columns C and D. They need a numeric value, and that value must be the largest acceptable value in the range to be counted.
    C2 (and filled right to column D, then both filled down to row 5):
        =COUNTIFS(Data :: $A,"<="&$B,Data :: B,TRUE)-SUM(C$1:C1)
    Two changes from the previous example:
    COUNTIFS is used to separate the Native and Foreign counts as well as the age range to be counted.
    The amount subtracted from each result is the SUM of the earlier results, and includes the text value in the first cell of the column (which is interpreted by SUM as a zero).
    See note below regarding my earlier formula.
    When the greyed columns are hidden and the checkbox in the Reorganize pane is checked, the two tables will appear as shown below:
    Close the reorganize pane, and the 'data entry form' is ready to use.
    To use, enter the age first, then check one of the boxes.
    As soon as one box is checked, the row will be hidden, and the next (unused) row will be shown.
    Regards,
    Barry
    Note regarding formula in my earlier post:
    The earlier formula will give erroneous results as it subtracts only the count directly above it from its count of persons in the age range 0-n.
    In E2 of that table, replace "-E1" with "-SUM(E1:E$1)
    Fill down to E8.
    Ignore the instructions (in that post) following "Fill down to E8."
    B

  • My broadband has 2MB download limit I need a counter to see how much I use.

    My broadband has 2MB download limit I need a counter to see how much I use. Please recommend one that I can start counting at the start of the month and be able to see how many MB I have downloaded at the end of the month to be able to work out what amount I need to pay for.

    Oops I mean a 2GB/month allowance. And I found Intego Content Barrier does it.

  • We need to transfer amount from one profit center to another profit centers

    Dear Gurus,
    We need to transfer amount from one profit center to another profit centers, wrongly posted how to do it?
    GL 600000 Sales a/c Domestic,
    around 5000 FI documents has post in worn profit center
    In the billing with material line items showing the correct profit center.
    we want reverse the GL 600000 a/c in our system what will be the impact in COPA Reporting. and how to do it?
    Pls advice me for the above said issues as we are nearing the year end pls help me.
    Thanks..Srirama

    Hai,
    You can do profit center posting 9ke0
    Profit center will derive from Material in your case it seems some subtitution changing the correct profit center in material master and putting this wrong profit center
    Profit center is not the deciding factor for COPA reports so there wouldn't be any impact in COPA report
    BR
    VSN

  • 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

  • Need a count for number of emails

    Hi,
    I need a count of emails coming to a mailbox in a specified date range. And i want that to be exported in an excel file.
    I was able to get the total count in a specified folder using the below cmdlet in PS but couldn't get during a specific time/date range:
    Get-Mailbox | Get-MailboxFolderStatistics | Where {$_.Name -match “Inbox|Sent Items|Deleted Items|Junk E-Mail”} | Select Identity, Name, ItemsInFolder | Export-csv c:\MailboxItemCount.csv
    Can the process be automated? As in, can i get the report generated day, week or
    month wise?
    Any help would be much appreciated.

    You would have to use Outlook or EWS for that.
    EWS calls can be scheduled.  Outlook will not run correctly without a full user interface and running under the scheduler is not supported.
    https://msdn.microsoft.com/en-us/library/office/dn535506%28v=exchg.150%29.aspx?f=255&MSPPError=-2147217396
    https://msdn.microsoft.com/en-us/library/office/dd633710(v=exchg.80).aspx
    ¯\_(ツ)_/¯

  • Need to count character from an xml

    Hi all,
    I need to count character from a field. and store it in a variable. My datasource is from xml file.
    Any ideas for the syntax?
    thanks in advance,
    Paolyn

    Use <?string-length(FIELD)?> to get the count of characters.

  • I need a count "UP" timer for a client.

    I have kind of a strange request, but it's from a strange client so it's not surprising.
    The client needs a counting UP timer, not a count DOWN timer, so please don't refer me to that widget, I already used it.
    The original countdown timer has expired, so now she wants a timer that will count the days, hours, minutes & seconds SINCE that timer expired.
    Website splash page: http://www.theapocalypse.ca so you can see what I mean.
    Is it possible to "crack" the existing widget and just "reverse" it, or is there something I can build in edge animate that will work?
    I know, WEIRD, but hey, a paycheque is a paycheque.
    Thanks guys!

    You may try this : http://www.tickcounter.com/countup/widget
    Thanks,
    Sanjit

  • TS3694 Error 3014 when trying to load ios6. I have cleared 2.5GB on the phone as it seems you need that ridiculous amount of space. Every time it just gives me 3014 error code within a minute of trying to download? Any help?

    Error 3014 when trying to load ios6. I have cleared 2.5GB on the phone (4s) as it seems you need that ridiculous amount of space. Every time it just gives me 3014 error code within a minute of trying to download? Any help?

    All,
    I thought it may be related to spaces in the path in which the script was called from. I tried having the ODBC command script in another directory but the same thing happens. It will give me the "CONFIGSYSDSN: Unable to create a data source for the 'Oracle in OraClient10g_home1' driver: Could not load the setup or translator library with error code -2147467259". As soon as the script is done running I can manually double click the script and it adds the DSN fine.
    Thanks,
    Clif Bridegum

  • Need to count values in Report

    I have a column in report which displays X. 
    I need to count total no of X
    Abhinav

    =SUM(IIF(Fields!Status.Value="X",1,0))
    Cheers,
    Vaibhav Chaudhari
    [MCTS],
    [MCP]

  • I need to count intermitte​nt high speed pulses from an outside source with cFP-CTR-50​2 and labview.

    I need to count intermittent high speed pulses from an outside source with cFP-CTR-502 and Labview 8.2 . I've found example code for generating pulses and creating intricate count setups but no straightforward examples of a simple counter. Any suggestions?

    Hello tinfish,
    I could not find a simple example that implements simple counting either, but it should be straightforward enough for us to try. Do you have the CTR module configured properly in MAX? If so, can you monitor the channels on your CTR 502 for input? Try connecting a square wave or some other digital pulse to the terminal to test the functionality of the counter module first (before programming). If you monitor the input channels with somethign connected you should see the count increment each time it sees a rising edge (assuming default configuration).
    Once you've verified that everything works in MAX, you can set up your CTR module in a LV 8.2 project. If you need help with this, refer to the help document (look in the "Configuring FieldPoint in LabVIEW" section):
    C:\Program Files\National Instruments\FieldPoint\documentation\Online Help\fplv.chm
    You should be able to just read a channel tag from your CTR 502 using an FP Read VI. (Simply drag the channel from your project onto the block diagram). Since counting is the default behavior of the 502, there is no special programming involved to make it work.
    I hope this helps -- if it's too high-level we can talk details about specific questions you have.  Have a good one!
    Charlie S.
    Visit ni.com/gettingstarted for step-by-step help in setting up your system

  • I need the Count to display "0" when the count = 0

    I'm creating a report that is run weekly.  Each week, one or more of the categories may turn up 0.  As this is being used as a sub report in another report, I need the count to show "0" when there is no data for the week as it is aligned with another sub report listing all the categories possible.
    The following is the formula I am currently working on:
    if(IsNull(Count ({UV_HRSRespClnByAreaDetail.SubType},{UV_HRSRespClnByAreaDetail.Stat})))
    then u201C0u201D
    else Count ({UV_HRSRespClnByAreaDetail.SubType},{UV_HRSRespClnByAreaDetail.Stat})
    This will not turn up 0, it still gives me a blank.  Any thoughts?

    Hi Aneisha
    You can check if the following formula works for you:
    numberVar cnt;
    cnt=(Count ({UV_HRSRespClnByAreaDetail.SubType},{UV_HRSRespClnByAreaDetail.Stat})
    if (IsNull(cnt)) then u201C0u201D
    else cnt;
    Hope this helps you.
    Regards
    Ashwini Yadav

  • Need to send notification to a specific person based on condition

    Please help.
    I need to send notification to a specific person based on condition. When a specific hold is placed on an invoice, send a notification to the Buyer who is referenced on the Purchase Order that is associated with that invoice. It will be an FYI notification.
    I'm looking at APINVHDN AP Hold Maiin Process. I thought possibly adding a notification into the "No" condition after the GET_APPROVER function since there would not be an approver on the invoice since it's on hold.
    Any ideas would be very much appreciated.

    Try the LiveCycle Designer forum.

  • I need to provide red color to the texbox control in list tile

    Hi,
    I need to provide red color to the texbox control in list tile, please reply if any one knows how to do it.
    Thanks,
    Vijay.

    Hi,
    I am afraid that this kind of enhancements/modifications needs some developing which requires a deeper knowledge of Mobile development and sufficient project experience.
    Unfortunately it is not possible to achieve this by doing "only" some customizing settings.
    Regards,
    Wolfhard

  • Return amount of times a character is in a string?

    Hello, quick question. As the title says, how can i return the amount of times a character is in a string? character such as 'a', 'b', etc. Thank you all, appreciate it!

    thank you for your help! so would this be correct? (s is the string)
              int amount = 0;
              for(int x = 0; x <= s.length(); x++)
                   if (s.charAt(x) == value){
                        amount++;
              return amount;

Maybe you are looking for

  • S.Cart creates Split PO, One S.Cart creates multiple PO's for each SC item

    Hi there SRM 5 SP04 SRM-ECC........we have 2 Situations first My S.Cart has Only 1 line item. (Not Ext Req) the System creates 2 PO's (PO xxxx412, PO xxxx388) for the same item. Both PO were "ordered". When I look in the "Display Changes" on the S.Ca

  • Publishing KM content in portal

    Hi, I need to upload and publish the templates (excel file)to the portal. I can able to upload the same in Content AdministrationàKMContentàFolderàNewàRight clickàUpload. But the same is not publishing in portal. As my requirement is to replace the o

  • Bridge CC / How to use all cores to generate JPEG images?

    Hi! Is there anyway to tell Bridge, that it should use all my cores to generate the JPEG images out of RAWs? Actually it uses less then 25% of my CPU performance. I've a Intel Core i7-2600 CPU @ 3,4 GHZ, with four cores and enabled hyperthreading, al

  • How do I turn off Optical Digital Output??

    My 15" macbook pro's digital optical output has turned on (the red light is on inside the headphone port) and i want to turn it off... but how??

  • How to setup System propterty in 10g EM

    Can anyone tell me how to setup System property in 10g EM or any system config file? My existing application has following code to access System property: this.logDir = System.getProperty("ServletLogDirectory"); My current application server is oas 4