Finding how many times unique strings occurs within a string

say for example i am given a string: String s= "AA BB CC AA BB CC DD DD FF EE FF AA", and i would want to know how many times each token (i.e "AA", "BB", "CC", "DD", "EE", "FF") occurs. (so in this "AA" occurs 3 times, "BB" occurs 2 time, "CC" occurs twice, "EE" once, etc). how would i go about doing this?
what i have so far is incomplete:
public void getOccurances(String s) {
String triple="";
StringTokenizer st = new StringTokenizer(s);
numOfTriples=st.countTokens();
while (st.hasMoreTokens()) {
triple=st.nextToken();
any help would be greatly appreciated .

any other ways without using arrays?Use a Map keyed by String (your tokens), and containing Integer objects representing the number of occurences.
I.e.:
Map occurenceCount = new HashMap();
// for each token myNewToken
if (occurenceCount.containsKey(myNewToken)) {
  int currentNumOccurences = ((Integer) occurenceCount.get(myNewToken)).intValue();
  occurenceCount.put(myNewToken, new Integer(currentNumOccurences + 1));
else {
  occurenceCount.put(myNewToken, new Integer(1));
}To display the associative array just use occurenceCount.toString()Linda

Similar Messages

  • How to find how many times a t code has been processed by a user

    How to find how many times a t code has been processed by a user I am not able to get the exact number from the ST03 or STAD/STAT transaction. I am requiring the specific number that this T code has been processed completely this many no of times for a specific period.

    You must be more precise with your question.
    How long is the time period which you want to check, few hours or several days or longer? And how many executions do you expect, 100, 10000 or millions?
    The STAD should help you, for the smaller numbers. There is no solution for the larger ones. Don't mix STAD and ST03, ST03 is aggregated STAD information
    and know only how often a transaction was executed in total.
    ST05 is no solution for your problem to much overhead, and yoou should trace only a short period.
    There is no tool to check usage of transactions in more detail because of privacy reasons.
    Siegfried

  • How to find how many times a program has been executed & by whom

    Can any one help me to find log of program : Details like how many times the program(T-Code) has been executed and by whom(User ID) and when

    Hi,
    sy-uname will give u the name of the person.
    sy-uzeit will give u the time of exection.
    Not sure about number of times of execution.
    <REMOVED BY MODERATOR>
    regards,
    Ramya
    Edited by: Alvaro Tejada Galindo on Mar 19, 2008 4:15 PM

  • Help appending how many times an event ID has occurred next to the unique Event ID.

    Hello,
    I am trying to figure out how to find how many times an event occurred and then append that next to the single  -unique Event ID.
    The closest I can find is the Sort-Object Count but I can't figure out how to get that work within the below script.
    Any help would be appreciated, the below script works already. but just doesn't have that Event ID count. 
    Thank you for any help. 
    Below is the
    script to pull all Event Logs for each server, filter them to only display Warnings, Failures, and FailureAudits for Application, System, and Security logs and then remove all duplicate EventIDs so only 1 of each is shown. it then exports that info into a
    .CSV per server.
    param([string]$days= "31" )
    $servers = @("Server1", "Server2" "Server3", "Etc")
    $user = Get-Credential
    #Set namespace and calculate the date to start from
    $namespace = "root\CIMV2"
    $BeginDate=[System.Management.ManagementDateTimeConverter]::ToDMTFDateTime((get-date).AddDays(-$days))
    $store = "C:\Powershell\MonthlyMaintenance"
    foreach ($computer in $servers)
    $filter="TimeWritten >= '$BeginDate' AND (type='Warning' OR type='Error' OR type='FailureAudit')"
    Echo "Pulling Event Logs for $computer ..."
    Get-WmiObject Win32_NTLogEvent -computername $computer -Filter $filter |
    sort eventcode -unique |
    select Computername,
    Logfile,
    Type,
    @{N='TimeWritten';E={$_.ConvertToDateTime($_.TimeWritten)}},
    SourceName,
    Message,
    Category,
    EventCode,
    User |
    Export-CSV C:\Powershell\MonthlyMaintenance\$computer-Filter.csv
    Echo "Done."

    Unfortunately adding that to the script just outputs a bunch of jargon:
    #TYPE Microsoft.PowerShell.Commands.Internal.Format.FormatStartData
    ClassId2e4f51ef21dd47e99d3c952918aff9cd
    pageHeaderEntry
    pageFooterEntry
    autosizeInfo
    shapeInfo
    033ecb2bc07a4d43b5ef94ed5a35d280
    Microsoft.PowerShell.Commands.Internal.Format.AutosizeInfo
    Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo
    9e210fe47d09416682b841769c78b8a3
    I did try adding it in various ways and removing the initial # Sort EventCode -unique | # and I just get the same jargon
    Am I adding it in wrong some how? 
    Thank you again for any help.
    param([string]$days= "31" )
    $servers = @("ComputerName")
    $user = Get-Credential
    #Set namespace and calculate the date to start from
    $namespace = "root\CIMV2"
    $BeginDate=[System.Management.ManagementDateTimeConverter]::ToDMTFDateTime((get-date).AddDays(-$days))
    $store = "C:\Powershell\MonthlyMaintenance"
    foreach ($computer in $servers)
    $filter="TimeWritten >= '$BeginDate' AND (type='Warning' OR type='Error' OR type='FailureAudit')"
    Echo "Pulling Event Logs for $computer ..."
    Get-WmiObject Win32_NTLogEvent -computername $computer -Filter $filter |
    sort eventcode -unique |
    select Computername,
    Logfile,
    Type,
    @{N='TimeWritten';E={$_.ConvertToDateTime($_.TimeWritten)}},
    SourceName,
    Message,
    Category,
    User,
    EventCode | Select Name,Count | FT -auto|
    Export-CSV C:\Powershell\MonthlyMaintenance\$computer-Filter.csv
    Echo "Done."

  • How do you find out how many times an app has been downloade

    Wondering where I can find out how many times an app from the app store has been downloaded?

    Are you asking if you can find out how many times an app has been downloaded from the app store? Or you asking if you can find how many times you have downloaded the app? If the former, you could try asking the developer. If the latter, none that I know of.

  • How to find a how many times a User logged in

    Experts,
    Is there a way where in I can find How many times a User Logged in to the system over a period of time.
    FYI...,
    I have a search over the forum but could not get the relevant solution for this. Had a trial search on TCodes SM04, SM20, STAD etc but could not find exact one for this.
    Please let me know is there any way where I could get the details on the above query.
    Thanks in adavnce.
    Regards,
    SRinivas

    HI,
    i found this fm RSAU_READ_FILE for sm20 , but i am not sure how to use it.
    I just made a search for this function and i got thisa link
    Check the reply by FabioBC in which he explains the mapping of fields to this function
    link:[http://www.sapfans.com/forums/viewtopic.php?p=799746&highlight=&sid=e8dca9480a775847b26ab57493f27eb6]
    Edited by: Keshav.T on Dec 3, 2010 8:16 PM

  • Statistics - To get how many time a report has been run

    Hi Gurus,
    I would like to know how many times each of the reports on the portal has been run. If I could get this by user id, that would be great.
    Do you know where I can get such information?
    Regards
    Mathew

    Hi Guys,
    This can not be done throug ST03/ST03N. For this you will have to either use the SAP delivered BI Statistics query which is built on 0TCT_M01 multiprovider. Make sure your data is upto date before you run the query.
    Disadvantage of teh SAP delivered query is, it will not give you result which is older than 24 hrs. So basically it gives you oppourtinity to analyze only last 24 hrs data. If you want to modify the query, you can copy the query and modify as per your requirement.
    Now coming to your question of finding how many times a report is run:
    Question is how many queries do you have in your report. If your report contains one query only, there is free char in the query called Frontend Session. Everytime your execute the query you will have a new Frontend session ID.
    So create a formula as counters for all values and set the exception aggregation based on Frontend session. This will give you the number of times each query executed. If you drill down by Users, you will get this numbers by users.
    - Danny.

  • Suddenly, I can't get the plugin scan page to open. I keep getting "Plugin Finding Service Error", no matter how many times I try, or wait. When I first opened it yesterday, it was scanning, then it disappeared and I got the error message.

    I have opened the plugin scanning page many times before, and have done some updating of plugins recently, but yesterday I couldn't bring up the scan, I keep getting "Plugin Finding Service Error", which says to "try again later". I believe what I updated most recently was Flash (I think). No matter how many times I push the "try again", or shut down Firefox and the webpage, I still get the error, and get nowhere!

    This problem has been occurring for the past two months. I have updated Firefox to version 3.6.16...including Flash Player to version 10.2.153.1 as instructed. I am able to click on the "Add-ons" tab and "find updates" for "Get Add-ons" and "Extensions." However, the "find updates" tab is not working for "Plugins."
    I followed one of your suggestions in your "troubleshooting plugins" topic (disabling the plugins...then enabling them after a check). That didn't work either. In fact, a message box would appear saying that Firefox has "disabled Flash" instead, which of course it did not, since I was able to confirm that the Flash Player update version was still intact. Unfortunately, it appears that updating the Flash Player through Firefox is not a standalone operation. Apparently it will not work properly unless a separate update is subsequently processed through Internet Explorer as well.

  • Tcode to find out how many times system started

    1. is there any tcode exists to find out that how many times that the system is started?

    Hi Ramesh,
    All this data is stored in log files. You can system start and stop details in SM21 but in SM21 data is available for few days only so if no restart has occured in that period you wont get data there. . If you want to check the last restart date and time check in ST04. You can also get this detail in dev_disp file.
    Please award points for useful answers.
    Regards.
    Ruchit.

  • Am I able to find out how many times my ICloud account has been accessed?

    Am I able to find out how many times my ICloud account has been accessed?

    I'm afraid iCloud doesn't provide access logs.

  • Finding query access frequency or how many times a query has been executed?

    Dear Experts
    I need to find the total number of access frequency of individual queries that are requested by the users say at a particular time.
    Say there are 20 distinct queries requested in the time difference of 3 hours. All of the 20 queries or some of the queries may be requested for more than 2/3 times at that time by other users. By the way say query Q1 is requested 5 times at that so its query access frequency or how many times this query is executed is 5.
    From where and how can I can find this counting of query access frequency or how many times a query has been executed at particular time or a session?
    Normally we know the there SQL history dynamic performance views or if it can be possible to query the Shared pool library cache for SQL area it may be possible to find the total number of execution time for a query. But how to find that if anyone knows, please help me about this.
    Regards-
    Engr. A.N.M. Bazlur Rashid
    OCP DBA

    That's one of the stats reported by statspack - assuming that your query does sufficient work to meet the thresholds for the standard report. Executions is of course one of the columns of v$sql so you might just wish to sample that yourself. Finally if you are on 11g and the sql you are interested is relatively low resource intensive and you are licensed for AWR then you can use the slightly madly named "colored sql" feature that ensures that a specific statement will always be sampled for AWR.
    Niall Litchfield
    http://www.orawin.info/

  • How many times a char showed up in a string

    Hi
    assume that i have this String:
    String s = "I have son and he has son and his son that has a son also"
    how can i determine how many times 's' showed up in this string?
    thanks

    there are many ways to accomplish this goal. All ways will require you to iterate through the String or char array, so the key is probably to simply avoid constructing new String instances on an unnecessary basis. Here is one way to accomplish what you are asking:
    for (int x = 0; x < string.length(); x++) {
    if (string.charAt(x) == 'i') {
    //record this index
    list.put(x);

  • Does anyone know how many times a newly purchased product (MB Air 2014) can be exchanged within the 14 day period?

    Does anyone know how many times a newly purchased product (MB Air 2014) can be exchanged within the 14 day period? I feel like the MB Pro would be a better fit for me, so I wanted to exchange my Air for the Pro. But also, if I end up not liking the Pro and want to go back to an Air, would I be permitted to do so with another exchange? (all still within the 14 day window after purchase of course).
    Also, are there any specifics I need to know in order to return my product and get a new one?  Obvioulsy, I would be sure to remove all of my personal files, music, etc...but is there anything else I need to do?
    And lastly, and im sure this question is irritating to you Mac wiz kids out there, but are the two models im comparing really all that different?  I just cant make up my mind and would love some pointers/suggestions/tips/info to help me figure out what model is best for me (the apple employee that was helping me in the store was actually not that helpful at all, if they were I wouldnt have to ask this question on a discussion board).  I do tons of multimedia things and download and enjoy music, tv shows, movies, all that stuff..and I used to love to burn dvds and cds (obviously cant do that with the MB Air now which totally bummed me out ).  Which model does anyone think I should stick with?  Id greatly appreciate some opinions! Really tho, help me out ppls! I'd love some helpful advice! I sometimes have problems making big/important/expensive decisions lol  I just really want to make sure i am getting the best model for all of my daily tasks and all of the things i actually do regularly on my computer.
    Oh, last lastly- I cant afford anything more than a 13" STANDARD MacBook Pro at the moment...soooo the Retina display is unfortunately not an option for me.
    Which is also a big bummer.but i think i can get over it...or beg someone to loan me an extra $200 lol
    Someone....Annnnyyyone....Pleeeeease....Heeelllllllp....
    Thanks

    Just play with each and figure out which one you want. I believe they only allow 1 exchange unless it is a defect issue. You can always return the exchanged item and rebuy what you want if they will not allow you to do multiple exchanges.
    But again, you need to really figure out which one you want.

  • Find out how many times the application was touched by a particular user

    Hello,
    can anyone please help me out with this issue.
    I want to find out how many times the application was accessed by a particular user,their session IDs for each of the applications in a particular workspace. I am using a role based authorization scheme for my application. I am using Oracle APEX 3.2 version. Are their any underlying APEX tables/Views to find out the above details.
    thanks,
    Orton

    Hi,
    Have you check views APEX_WORKSPACE_ACCESS_LOG and APEX_WORKSPACE_ACTIVITY_LOG
    Regards,
    Jari
    Edited by: jarola on Oct 20, 2010 7:37 AM
    This might help also
    http://download.oracle.com/docs/cd/E14373_01/appdev.32/e11838/advnc.htm#CHDDHGJI

  • How to find out how many times an album has been burned to cd

    how to find out how many times an album has been burned to cd

    You can't.
    and the restriction (lwhich limits burning a specific playlist to audio CD) applies only to a specific playlist with DRM songs.

Maybe you are looking for