How to Search and Array for multiple occurrences of a value

Hi,
I am trying to search an array of doubles for a number and report the index location(s) of a number. I.e. -allow for repetition. Search and report all index[i] where the number is contained in the array. For example I have
double[] myInputArray = new double[5];
double[] myInputArray = { 1, 2, 3, 3, 5 }I know how to search through the array ONCE and return the first occurrence of a number:
public double GetIndexOf(double Number) {
    for (int i=0; i<myInputArray.length; i++) {
         if (myInputArray[i] == Number){
              return(i);
    return(-1);
  }How do I expand this code to report multiple index[i] locations if the number reoccurs in the array like the number 3 does in my example array above?

The way the Java libraries do this type of operation (String.indexOf(), etc) is to specify the starting index along with what you want to find.
Changing your example slightly (notice how I fixed your naming and more importantly, your return type):
public int indexOf(double num) {
   return indexOf(num, 0);
public int indexOf(double num, int fromIndex) {
    for (int i=fromIndex; i<myInputArray.length; i++) {
         if (myInputArray[i] == num){
              return(i);
    return(-1);
//usage to get all indices:
for ( int index = -1; (index = indexOf(num, index+1)) != -1; ) {
   System.out.println(index);
}Note that due to how floating point numbers work, you may find doing this on doubles (or any other operation that uses == with double arguments) to give you unexpected results.

Similar Messages

  • How do I search and replace for invisibles in Pages 5.5.2?

    Three related problems all involving search and replace for invisibles.
    1. A block of text where all double returns need to become single returns.
    2. A block of text where all returns need to be replaced with a single word space.
    3. A block of text where all double word spaces to be replaced with a single word space.
    Pages 09 could do all three this handily. How can these be done in Pages 5.5.2?
    Appreciated.

    Here are screenshot of my attempts to make reducing double returns to one. First up selection of a double return:
    Copy to the clipboard. Do a Command-F. Here's the resulting dialogue:
    I paste in the contents of the clipboard:
    Note the Search field no longer has an empty slot selected. Something is clearly in there, but no instance of whatever is has been found. Nevertheless, I proceed to set up the Replace field by selecting a single return:
    Copy that to the clipboard and paste into the Replace field:
    Nothing to search for and therefore nothing to replace. Am now wondering what that little scoop to the right of the eyeglass icon might indicate. Clicking on it reveals this:
    Definitely not "a solution that just works."

  • How to FaceTime and iMessage on multiple apple devices with one iTunes account

    We recently received iPad 2's for Christmas and was looking for some advice on how to FaceTime and iMessage on multiple apple devices with One iTunes Account (Apple Id).  I have created or attached other e-mail addresses to our apple id but do not know how to use them on the new devices.  Our home MacBook Pro uses our main apple id for FaceTime.  The iPads have been setup with the main apple id w/o being able to use FaceTime and iMessage.
    Please Help...
    I appreciate the help and support.

    P and V-
    If you are trying to connect to someone with a different Apple ID, I think all the devices should work, but one at a time.
    The problem is when you try to connect between two with the same Apple ID.  Once the calling device tries to make the connection, it finds the second device to be "busy".  That is where each needs to use a different E-Mail address when setting it up.
    On iOS devices, when you press the Home button to exit an App, the App may still be active in the background, even when the device is sleeping.  If FaceTime or iMessage is merely being active that way, it may be enough to "tie up" the E-Mail address.
    From the Home screen, double click your Home button.  You will see a list of recent Apps along the bottom of the screen.  Press and hold on one of them until they start to wiggle.  You will then see a red minus sign on each.  Pressing the minus sign will remove an App from the list, and stop it from working in the background.  (Click the Home button to stop the wiggling, and again to hide the recent Apps.)
    Fred

  • Global Search and Replace for Scrambled/Garbled Characters

    So I exported a bunch (over 3000) contacts from my Outlook on Windows by using Outlook2Mac, and also tried just using a straight CSV export. But the Chinese characters came out all garbled, and I no longer have the use of that Windows machine anymore.
    Here's an example:
    Name: ∂¿¨¸™K (May Huang)
    Job Title: ±M§·∏g≤z
    Dept: ¿Á∑~≥B/ODM∑~∞»≥°
    Company: ®Ù•fl∞ͪ⁄
    Address:
    §≠™—∂m§≠≈v§≠∏Ù15∏π
    •x•_ø§
    •x∆W
    I figure I can slowly piece together most of it by doing lots of global search and replaces -- for instance, "•x∆W" should be "台灣" (Taiwan) -- and changing each characters I know one by one.
    Problem is, I can't figure out how to do a find and replace! Can anyone help me out?
    Thanks in advance!
    PowerBook G4 17   Mac OS X (10.4.5)  

    But for the sake of getting a solution to the
    original problem, I wasn't able to export the vCards
    from AddressBook and then do what you said. For some
    reason, I couldn't open the .vcf file in TextEdit;
    kept telling me that the file wasn't encoded in
    "Traditional Chinese (Windows, DOS)" format.
    You need to use the Open dialogue in TextEdit and open the .vcf in something that it will accept. When you export the stuff from Address book, it indeed is not in Trad Chinese.
    I don't have your stuff, so I can't be exactly sure, but it should work something like this. You export everything from Address Book. Use the Open dialogue of TextEdit to open the file, probably as UTF-8. Save as MacRoman. Open again as Trad Chinese (Windows). Save as UTF-8. Reimport. You may need to experiment to find what works right.

  • In Pages, how to search and replace text involving invisible characters?

    In Pages documents, how to search and replace text involving invisible characters, colors and font sizes—a task which is so easy in Mircosoft Word?

    I read that an older version of Pages allowed users to enter special characters in the search/replace fields, but this did not work for me.
    Here: http://www.macworld.com/article/1156533/pagesspecialcharacters.html
    I still am looking for a way to do this.

  • How to search and remove all exact words

    How to search and remove all exact words, I have tried adobe 11 Pro and I still need to know how to do this

    That works well for replace or deleting one at a time, I need to search the doc and delete all found and not change formatting
    Thank you for your help

  • How to apply List box for multiple selection of rows  in ALV report ?

    Hi Exprots,
    1: How to apply List box for multiple selection of rows  in ALV report ?
    Thanking you.
    Subash

    hi,
    check the below program.
    REPORT zalv_dropdowns.
    *Type pools declarations for ALV
    TYPE-POOLS : slis.
    *data declarations for ALV container,ALV grid, Fieldcatalogues & layout
    DATA: g_grid  TYPE REF TO cl_gui_alv_grid,
          g_custom_container TYPE REF TO cl_gui_custom_container,
          gt_fieldcat TYPE lvc_t_fcat,
          gs_layout TYPE lvc_s_layo.*INTERNAL TABLE AND WA DECLARATIONS FOR t517 A table
    DATA: gt_outtab TYPE STANDARD TABLE OF t517a INITIAL SIZE 0,
          wa_outtab TYPE t517a.
    START-OF-SELECTION.*Call to ALV
      CALL SCREEN 600.*On this statement double click  it takes you to the screen painter SE51.
    *Create a Custom container and name it CCONT and OK code as OK_CODE.
    *Save check and Activate the screen painter.
    *Now a normal screen with number 600 is created which holds the ALV grid.
    PBO of the actual screen , Here we can give a title and customized menus
    Here we also call the subroutine for ALV output.
          MODULE PBO OUTPUT                                             *
    MODULE pbo OUTPUT.
      PERFORM alv_output.
    ENDMODULE.                    "pbo OUTPUT
          MODULE PAI INPUT                                              *
    MODULE pai INPUT.
    ENDMODULE.                    "pai INPUT
    *&      Form  BUILD_FIELDCAT
    FORM build_fieldcat.
    DATA ls_fcat TYPE lvc_s_fcat.
    *Build the field catalogue
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name = 'T517A'
        CHANGING
          ct_fieldcat      = gt_fieldcat.
    To assign dropdown in the fieldcataogue
      LOOP AT gt_fieldcat INTO ls_fcat.   
    CASE ls_fcat-fieldname.
       WHEN 'SLART'.
    *is the first list box
            ls_fcat-drdn_hndl = '1'.
            ls_fcat-outputlen = 15.
            MODIFY gt_fieldcat FROM ls_fcat.
    is the second list box    
    WHEN 'ABART'.       
            ls_fcat-drdn_hndl = '2'.
            ls_fcat-outputlen = 15.
            MODIFY gt_fieldcat FROM ls_fcat.   
    ENDCASE.
      ENDLOOP.
    ENDFORM.                    "build_fieldcat
    *&      Form  ALV_OUTPUT
    FORM alv_output .*Create object for container
      CREATE OBJECT g_custom_container
             EXPORTING container_name = 'CCONT'.
    *create object for grid
      CREATE OBJECT g_grid
             EXPORTING i_parent = g_custom_container.
    Build fieldcat and set column
    *Assign a handle for the dropdown listbox.
      PERFORM build_fieldcat.
    *Build layout
      PERFORM build_layout.
    Define a drop down table.
      PERFORM dropdown_table.
    *fetch values from the T517A table
      SELECT * FROM t517a INTO TABLE gt_outtab.
    *Display ALV output
      CALL METHOD g_grid->set_table_for_first_display
        EXPORTING
          is_layout       = gs_layout
        CHANGING
          it_fieldcatalog = gt_fieldcat
          it_outtab       = gt_outtab.ENDFORM.                               "ALV_OUTPUT
    *&      Form  dropdown_table
          text
    -->  p1        text
    <--  p2        text
    FORM dropdown_table.*Declarations for drop down lists in ALV.
      DATA: lt_dropdown TYPE lvc_t_drop,
            ls_dropdown TYPE lvc_s_drop.
    First SLART listbox (handle '1').
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '01 Primary school'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '1'.
      ls_dropdown-value = '02 Lower Secondary'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '1'.
      ls_dropdown-value = '03 Upper Secondary'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '04 Professional School'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '05 College'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '06 University'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '1'.
      ls_dropdown-value = '09 Other Establishment'.
      APPEND ls_dropdown TO lt_dropdown.* Second ABART listbox (handle '2').  ls_dropdown-handle = '2'.
      ls_dropdown-value = '10 Primary School certificate'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '2'.
      ls_dropdown-value = '20 Lower secondary/Junior high'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '30 High school diploma(B-levels)'.
      APPEND ls_dropdown TO lt_dropdown.
      ls_dropdown-handle = '2'.
      ls_dropdown-value = '31 Vocational'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '32 Matriculation'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '40 Specialist vocational certificate'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '50 College degree Level1'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '51 College degree Level2'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '52 Masters degree'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '60 Univ Degree level1'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '61 Bachelors degree'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '62 Masters degree'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '63 Licenciate'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '64 Doctors Degree Ph.D'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '89 None'.
      APPEND ls_dropdown TO lt_dropdown.  ls_dropdown-handle = '2'.
      ls_dropdown-value = '90 Unknown'.
      APPEND ls_dropdown TO lt_dropdown.*method to display the dropdown in ALV
      CALL METHOD g_grid->set_drop_down_table
        EXPORTING
          it_drop_down = lt_dropdown.ENDFORM.                               " dropdown_table
    *&      Form  build_layout
          text
    *layout for ALV output
    FORM build_layout .  gs_layout-cwidth_opt = 'X'.
      gs_layout-grid_title = 'ALV DROPDOWN LISTS'.
      gs_layout-no_toolbar = 'X'.ENDFORM.                    " build_layout
    endform.
    Edited by: S.r.v.r.Kumar on Jun 1, 2009 2:48 PM

  • HT5534 How do i purchase keynote for multiple users without a MAC computer?

    How do i purchase keynote for multiple users without a MAC computer?

    Guy, you see, I understand you need to be with the Mac you want to download Keynote.
    And yeah, Keynote only works with the Mac OSX and iOS

  • How to create one TO for multiple TRs

    Dear All,
    how to create one TO for multiple TRs, kindly suggest me
    Regards,
    balu

    As for your question: it is discussed in sAP online help:
    http://help.sap.com/saphelp_erp60_sp/helpdata/en/c6/f841f24afa11d182b90000e829fbfe/frameset.htm
    Sorry I misunderstood your question.
    The above mentioned solution won't create one single TO from multiple TR.
    Edited by: Csaba Szommer on Aug 11, 2010 9:46 AM

  • How set  UserName and Password for HTTP Basic Authentication for a servlet

    Hi..
    How set UserName and Password for HTTP Basic Authentication for a servlet in JBoss server?
    Using Tomcat i can do it .(By setting roles in web.xml, and user credintails in tomcat-user.xml).
    But i dont know how do it in JBOSS..
    I am using Netbeans and Eclipse IDEs.. Can we do it by using them also!?
    Thank u

    Hi Raj,
    You can do this by creating a Login screen for the users and check the authentication of each user in PAI i.e. PROCESS AFTER INPUT.
    Store the user information in a database table and check the username and password when the user enters it.
    You can display password as *** also. For this double click on input box designed for password and goto Display tab. Select Invisible in the list and check it.
      CASE sy-ucomm.
        WHEN 'BACK'.
          LEAVE PROGRAM.
        WHEN <fcode for submit>.
          SELECT SINGLE uname pwd
           FROM <DB table>
           INTO (user, pass)
           WHERE username = user AND
                   password = passwd.
          IF sy-subrc = 0.
    <Go to next screen for further processing>
          ELSE.
    <Display Error message and exit>
          ENDIF.
      ENDCASE.
    Regards,
    Amit
    Message was edited by:
            Amit Kumar

  • How to manage one wsp and dll for multiple clients in farm environment

    1. There is a product which is developed using C sharp , jquery,CSS and sharepoint object models which have been packaged into .wsp file. Whenever we introduce new functionality to the product we used to branch the
    previous code as a version , say Version 1.0 and new functionality of the product will in another solution. This is how we are managing the code in TFS as versions. Each newer version will have new functionalities. We do not give latest functionality for all
    the clients. Each client is having its own version of functionality. Technically in order to access the functionality, the wsp solution should be present in the solution repository which is available in SharePoint central administrator site. This solution
    will be deployed on the client’s site. We are following the above process in SharePoint standalone installation where we used to purchase dedicated server per client and installed sql, SharePoint foundation 2010 as standalone installation and adding the client
    related version of the code to the solution repository. Later host on the site which is created for that client purpose. This process is same for all the clients where we purchase individual server for each client .
        Now we want to host our product in farm environment of sharepoint foundation 2010 where we are going to try 3 level architecture. 
    • SQL Server-In this sever we are going to install sql server 2008R2 standard edition. Which should serve the database service for all the web applications/sitecollections which we are going to create in Web front end server.
    • Application server- In this server we are going to install the sharepoint as farm and will install search server express for serving search functionality for our product
    • Web front end server- In this server we are going to add this server to Sharepoint farm which we have created in application server. Here we are going to create web applications and site collections for all the clients.
    In this scenario how to manage multiple versions of same wsp solution?
    Another major issue w.r.t the architecture of the product and new approach for client deployment as follow.We have CSS, jquery files for serving the functionality.These files have been mapped to 14 hive folder.If any changes we do one of the jquery file or
    css file which is meant for latest version and not for old version, then how to manage this new functionality for that particular css or jquery file in 14 hive folder, since there is only one 14 hive folder. What is the best practice to make this happen? Another
    thing is, how to manage dll files for individual client?

    It sounds like you have a farm scoped solution at work. In that case you can only have a single instance of it per farm, you'd have to branch each version so they appear to be seperate solutions entirely (thus ruining your clients upgrade process).
    Bluntly i don't think a single farm can manage all your user environments.

  • How to search a genre for a specific title in the iTunes Store and have a concise result

    How can I search the iTunes for say:  Title = "Satisfied" and Genre = "Christian & Gospel" and have a result with only tunes that start with "Satisfied" within the Genre "Christian & Gospel"

    Hi Aravinda,
    SharePoint list column (or site column used as a list column), after we create a list item and make sure column has value, and start a full crawl, then a Crawled Property format as ows_thisColumnName (e.g. ows_Description in this case) will be
    generated for this column, you can check the search service application from Central Administration site, find the Crawled Property ows_Description and make sure the option "include values for this property in the search index" is checked, and
    re-start a full crawl, then check results again.
    Thanks
    Daniel Yang
    TechNet Community Support

  • How to design interactive pdf. for multiple additions and saves???

    Using LiveCycle designer -  Can anyone clarify how we can let others make multiple additions and saves to an interactive pdf. I created in Live Cycle Designer 8.2.1...
    I have created an interactive pdf. with LiveCycle designer and sent to client.
    Is there any way I can give them ability to save the pdf. make  multiple additions and saves and send back when they have completed it?
    or even pull up the file make changes and resend at some point in the future without having to fill in all form field again?
    Thxz much,
    JR

    Sorry but this is the wrong forum (this is for the Collaboration Services). You may want to try the LiveCycle Designer forum:
    http://forums.adobe.com/community/livecycle/livecycle_es/livecycle_designer_es

  • How to search in iPhoto for list of titles (an OR search instead of AND)

    Background: I upgraded from iPhoto 08 to 09 and lost my aliases to my originals. Lesson learned, I'm now re-importing all originals to a new managed library. However, I want to recover my meta data about the photos (mainly the "my ratings"). Luckily, I have a spreadsheet of all the photo titles that I need to set the rating.
    Problem: I need to bulk search for the photos instead of search for them one at a time. In the search box in iPhoto, if I paste in all the photo titles no results come back (it's doing an AND search). I need it to do an OR search and allow any number of titles to be entered and return all the photos that match. I was thinking iPhoto would be able to use the same syntax as Spotlight, but it doesn't seem to do that.
    Question: Is there a way to do this? I tried building a smart album, but that has the same problem. You have to enter in the titles one by one. Any way to have a list of titles and search for all of them at once? Any back door ways?
    Message was edited by: hillbillyRockstar

    Well, that would work. However, that means I have to enter each title individually and click the "+" each time. I have about 1500 photos to enter this way. I know, how picky am I...
    I guess what I was hoping for would be somewhere I could just paste in all the titles into one field and have it do the "any" search from just one field.

  • One Search service application for multiple web applications in a single server

      We are planning to host 17 Web applications in a single Server. Do I need to create search service application for each web application or I need to create one  Search service application , create a Content source for each web
    application and create a Result source for filtering. Which is the best approach. And which approach takes more RAM memory.
       In my application I am using Search web part, "Recently Changed Items", "Popular Items" web parts. when I created only one one  Search Service application for all web applications and using Result sources ,
    I am not getting the results. What could be the problem.

    Hi,
    One SSA is ok, but you should think about access rights. If the access is clear cut between all the web apps you should be ok with one SSA. Multiple result sources limiting on content source also works, but could easily be bypassed.
    Multiple SSA's will eat up RAM/CPU like a mother :)
    As for popular etc.. it could be due to how those sources are set up, but haven't investigated or tested this much.
    Thanks,
    Mikael
    Search Enthusiast - SharePoint MVP/MCT/MCPD - If you find an answer useful, please up-vote it.
    http://techmikael.blogspot.com/
    Author of Working with FAST Search Server 2010 for SharePoint

Maybe you are looking for