Best way to find a string contains a list of keywords

Could anyone do any different or is this good enough?
@ String line Line to be tested
@ String keyline Line that contains comma delimited keywords
private boolean containsAll(final String line, final String keyline) {
        int count = 0;
        String[] keywords = keyline.split(",");
        for (String keyword : keywords) {
            if (line.indexOf(keyword.trim()) != -1) {
                count++;
        return count == keywords.length;
    }Is Regex faster?
Thanks.

geeflow wrote:
Well! It looks that in my context the method needs to return FALSE if test string does not have ALL the items in the key word line. In my context, if keyword line = "", I run into trouble. That's an example of new requirements making the solution not good enough. Here's a way to incorporate splitting the keyword into the method, that should also eliminate the need for calling trim():
private boolean containsAll(String line, String keyLine) {
    for (String keyword : keyLine.split("[, ]+")) {
        if (!line.contains(keyword)) return false;
    return true;
} If line is empty, this will return false; no problem there. If keyLine is empty, you'll get a false positive. And if either one is null, you'll get a NullPointerException; you should probably check for those conditions first so you can throw a more helpful exception. You also have a case issue: "Double" is not the same as "double". You can get around that problem by using indexOfIgnoreCase() instead of contains().
So I am still wondering if I can get away with not using a counter.Yes, you can--at least until the next time the requirements change. ;-)

Similar Messages

  • What is the best way to find a file on the servers disk without using web.xml?

              What is the best way to find a file on the servers disk without using web.xml?
              I want to find a configuration file not contained within the war file I have
              created. Is there a way to pass information into the ServletContext with out
              rebuilding the ear or war files? Tomcat 4.0 can do this in its server configuration
              files. Does BEA have the equivalent?
              Regards,
              Eric
              

    You can specify the path to the file as a system property
              eg
              java -Dconfig.file.location=./mydirecotry/myfile.txt com.test.MyApp
              "Eric White" <[email protected]> wrote in message
              news:[email protected]..
              >
              > What is the best way to find a file on the servers disk without using
              web.xml?
              > I want to find a configuration file not contained within the war file I
              have
              > created. Is there a way to pass information into the ServletContext with
              out
              > rebuilding the ear or war files? Tomcat 4.0 can do this in its server
              configuration
              > files. Does BEA have the equivalent?
              >
              > Regards,
              > Eric
              

  • There are way too many photos on my internal hard drive. I have older libraries, and newer libraires in iPhoto and Aperture 2.  What is the best way to find and reduce the number of duplicate photos/libraries  before upgrading to Aperture 3?

    There are way too many photos on my internal hard drive. I have older libraries, and newer libraires in iPhoto and Aperture 2.  What is the best way to find and reduce the number of duplicate photos/libraries  before upgrading to Aperture 3?

    Sharon-
    Good idea.
    Back up first.
    I would probably wait for the merge function of the latest version before merging. Be sure to verify every merge.
    Merge Libraries, then from within Aperture move images to referenced on external hard drives.
    HTH
    -Allen

  • What is the best way to find the size of files?

    What is the best way to find the size of my files?

    Select a file or folder in the Finder and choose Get Info from the File menu.
    (125056)

  • Best way to find an Ipad 2 wifi only that has been stolen or lost? Have "Find My Iphone" installed but device not turned on. Please Help!

    Best way to find an Ipad 2 wifi only that has been stolen or lost? Have "Find My Iphone" installed but device not turned on. Please Help! Left in Spirit Airplane in Chicago and no where to be found

    Apple (and no one else) can not assist (with serial number or iCloud) in finding a lost or stolen iPad.
    Report to police along with serial number. Change all your passwords.
    These links may be helpful.
    How to Track and Report Stolen iPad
    http://www.ipadastic.com/tutorials/how-to-track-and-report-stolen-ipad
    Reporting a lost or stolen Apple product
    http://support.apple.com/kb/ht2526
    iCloud: Locate your device on a map
    http://support.apple.com/kb/PH2698
    Report Stolen iPad Tips and iPad Theft Prevention
    http://www.stolen-property.com/report-stolen-ipad.php
    How to recover a lost or stolen iPad
    http://ipadhelp.com/ipad-help/how-to-recover-a-lost-or-stolen-ipad/
    iCloud: Locate your device on a map
    http://support.apple.com/kb/PH2698
    How to Find a Stolen iPad
    http://www.ehow.com/how_7586429_stolen-ipad.html
    What NOT to do if your iPhone or iPad is lost or stolen
    http://www.tomahaiku.com/what-not-to-do-if-your-iphone-or-ipad-lost-or-stolen/
    Apple Product Lost or Stolen
    http://sites.google.com/site/appleclubfhs/support/advice-and-articles/lost-or-st olen
    Oops! iForgot My New iPad On the Plane; Now What?
    http://online.wsj.com/article/SB10001424052702303459004577362194012634000.html
    If you don't know your lost/stolen iPad's serial number, use the instructions below. The S/N is also on the iPad's box.
    How to Find Your iPad Serial Number
    http://www.ipadastic.com/tutorials/how-to-find-your-ipad-serial-number
    iOS: How to find the serial number, IMEI, MEID, CDN, and ICCID number
    http://support.apple.com/kb/HT4061
     Cheers, Tom

  • Best way to find the source of my iMac's constant crashing

    My iMac is crashing 1-2 times a day. The crashes are strange in that I can still move my mouse cursor, but everything on screen is frozen. They tend to happen while using Photoshop or Safari, but during menial tasks (resizing a 3MB photo or opening a new tab), and they happen in other programs as well…even just using the Finder. The crashes have happened over the last six months but only recently became for frequent – used to be a weekly occurence, now it's happening every day.
    I haven't installed anything new that might be the culprit, except for GoToMyPC which I've since uninstalled. What is the best way to find out what's causing these crashes?
    I've been toying with the idea of starting with a clean slate – wiping out my drive and reinstalling Mountain Lion – to get my Mac back to factory condition. What's the best way to do this? I don't want to go off of a backup because I don't want to bring over any bad processes or programs. So what's the best way to bring over all my files? Should I just copy over the particular files from the Home folder? Any chance I would be bringing over corrupted files?

    Reinstalling Lion/Mountain Lion Without Erasing the Drive
    Boot to the Recovery HD: Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Repair the Hard Drive and Permissions: Upon startup select Disk Utility from the main menu. Repair the Hard Drive and Permissions as follows.
    When the recovery menu appears select Disk Utility. After DU loads select your hard drive entry (mfgr.'s ID and drive size) from the the left side list.  In the DU status area you will see an entry for the S.M.A.R.T. status of the hard drive.  If it does not say "Verified" then the hard drive is failing or failed. (SMART status is not reported on external Firewire or USB drives.) If the drive is "Verified" then select your OS X volume from the list on the left (sub-entry below the drive entry,) click on the First Aid tab, then click on the Repair Disk button. If DU reports any errors that have been fixed, then re-run Repair Disk until no errors are reported. If no errors are reported click on the Repair Permissions button. Wait until the operation completes, then quit DU and return to the main menu.
    Reinstall Lion/Mountain Lion: Select Reinstall Lion/Mountain Lion and click on the Continue button.
    Note: You will need an active Internet connection. I suggest using Ethernet if possible because it is three times faster than wireless.
    To do an Erase and Install of Mountain Lion:
    Install or Reinstall Lion/Mountain Lion from Scratch
    Be sure you backup your files to an external drive or second internal drive because the following procedure will remove everything from the hard drive.
    Boot to the Recovery HD:
    Restart the computer and after the chime press and hold down the COMMAND and R keys until the menu screen appears. Alternatively, restart the computer and after the chime press and hold down the OPTION key until the boot manager screen appears. Select the Recovery HD and click on the downward pointing arrow button.
    Erase the hard drive:
      1. Select Disk Utility from the main menu and click on the Continue button.
      2. After DU loads select your startup volume (usually Macintosh HD) from the
          left side list. Click on the Erase tab in the DU main window.
      3. Set the format type to Mac OS Extended (Journaled.) Optionally, click on
            the Security button and set the Zero Data option to one-pass. Click on
          the Erase button and wait until the process has completed.
      4. Quit DU and return to the main menu.
    Reinstall Lion: Select Reinstall Lion/Mountain Lion and click on the Install button.
    Note: You will need an active Internet connection. I suggest using Ethernet if possible
                because it is three times faster than wireless.

  • Best Way To Find Duplicate Songs in ITunes

    I have 3000+ songs in ITunes. I know I have a few duplicates. What is the best way to find them? Just sort by name and look? Or is there a simpler way?
    Thanks.

    Oh crap <insert egg on face here>
    I am so used to Windows MEdia Player, that I must have just skimmed over the menus.
    Thanks!

  • Way to find transaction code - if not listed in system-- status

    Hi friends
    way to find transaction code - if not listed in system--> status
    ex:
    spro- sd - sales -sales documents- sales document item -define item categories
    I didn't find T-code for this path from <b>system -->status</b>
    Please let me know the ways to find out exact T- codes.
    Thanks
    Prasad

    Hi Prasad, once you are in
    spro- sd - sales -sales documents- sales document item -define item categories,
    go to Additional Information-> Additional Information -> Display Key -> IMG Activity
    this will show you a code, in this case SIMG_CFMENUOLSDVOV7
    take last four caracters, this is transaction code: VOV7.
    Please reward if you find this useful.
    Regards,
    Efren

  • What is the best way to find what version of PDF Reader from Adobe is installed on a windows OS?

    Hi,
    I am developing a .Net App in which i want to find which version of PDF Reader from Adobe is installed on an Windows OS.
    It can be any of the software
    Adobe Reader
    Adobe Acrobat X Pro
    or any other.
    How to find out?

    The best way would be to find and query the AcroRd32.exe executable. The file version information is stored in the executable itself.
    There are lots of places in the registry that you could also potentially access relevant information.
    For example the uninstall string:
    HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
    Contains a string that you could use to search for the application version.
    How you would do this in .NET I'm not sure but you would use some kind of text search command to search for the relevant text and then use "if exists" condition.

  • Find if string contain letters

    HI All,
    How can I find if in string contain lettesr (in all the languages ),for instance
    if lv_string = '1a11'.
    subrc = 0.
    if lv_string = 'aaaa'.
    subrc = 0.
    if lv_string = '1111'.
    subrc = 4.
    Best regards
    Joy
    Moderator Message: FAQ. Thread locked.
    Edited by: Suhas Saha on Nov 17, 2011 5:40 PM

    There are a few ways to do that. Check out the String class or Regex for one that suits but
    myString.indexOf(whatIWantToFindString)is an old favorite. It returns -1 if the sequence is not there, or the starting index if it is. The javadocs are your friends.
    regards

  • What is the best way to handle collections that contains different object

    Hi
    Suppose i have two class as below
    class Parent {
           private String name;
    class Child extends Parent {
          private int childAge;
    }I have a list that can contains both Child and Parent Object but in my jsp i want to display a childAge attribute ( preferrably not to use scriplet )
    what is the best way to achieve this?

    Having a collection containing different object types is already a bad start.
    How are parent and child related to each other? Shouldn't Child be a property of Parent?
    E.g.public class Parent {
        private Child child;
    }In any way, you could in theory just check Object#getClass()#getName(), but this is a nasty design.

  • Find Whether String Contain Sequence Of Character Or Not

    <b>
    hello friend,
    I am to the new java. I need to findout whether the string contain sequence of character or not. I tried like this
    personLastName.length()> 0
    It will return true even my string contains space. Is there any other method in java to find out ?
    Thanks

    There are a few ways to do that. Check out the String class or Regex for one that suits but
    myString.indexOf(whatIWantToFindString)is an old favorite. It returns -1 if the sequence is not there, or the starting index if it is. The javadocs are your friends.
    regards

  • What is the best way to find and apply the samples in the sap library

    I am a fresh man in the process of learning sap .
    Mainly aim at the MM and SD model .
    They all say that the best way to accomplish the task is to follow the sap on-line help.
    because i don`t know the struts of the library , so to find what i need in the library becomes impossible for me as the library includes a lot of files .
    so please some one help me to direct the struts of the library and teach me the way how to find what i want ?
    thanks

    Hi,
    This forum is for BPX. Post Solution related quries in SAP Solution Forums.
    You can access MM and SD help at:
    http://help.sap.com/erp2005_ehp_02/helpdata/en/80/ea89395eb58c4f9d0c3e837cf0909d/frameset.htm under Logistics
    or http://help.sap.com/ -> SAP ERP -> Choose Release (for example SAP enhancement package 2 for SAP ERP 6.0) -> SAP ERP Central Compoennt (MM and SD under Logistics)
    From Materials Management Link you can navigate further to Purchasing, Inventory Management etc. From Sales and Distribution you can naviate further: Sales, Billing etc.
    For example to see help regarding Purchase Orders:
    You would first expand Logistics and choose Materials Management in Help Link for ERP Central Component. Here, choose Purchasing Node which will take you Purchasing Help screen -> Click and Purchase Orders Node and Expand the same for more information regarding Purchase Orders.
    You should be comfortable with SAP help link.
    Regards,
    Naveen.
    Search the forum with keywords before posting the query.

  • Best way to find and copy files

    If i have a list of 2000 file names and want to find:
    if they exist in folder x
    then copy to folder y
    else
    output an error messege to txt file.
    What would the most efficient way to do this be? So far i've used listFiles() and put a >HUGE< directory listing into an Array. Then I did a comparison for each file name in the list against the array. I know this cant be the most efficient way. I posted earlier in the board but for some reason NO one answered. Can anyone suggest and easier way to do this? and what is the best way to copy files in java? opening a bufferwriter etc? Essectially, im doing a restore from multiple backup directories to the original directory. Please help me if you can take the time.
    Thank you,
    jon

    If i have a list of 2000 file names and want to
    find:
    if they exist in folder x
    then copy to folder y
    else
    output an error messege to txt file.
    What would the most efficient way to do this be?In a loop just read and write each file. If it does not exist, print an error.
    So far i've used listFiles() and put a >HUGE< directory listing into an Array. A directory with a million entries is a HUGE directory, I guess you only have a few thousand.
    I wouldn't bother reading the files into memory, you only need 2000 of them.
    Then I did a comparison for each file name in the list against the array. The OS will do this for you when you try to open the file, which you will have to do anyway to copy it.
    I know this cant be the most efficient way. More efficient way, don't do it at all.
    I posted earlier in the board but for some reason NO one answered. Perhaps the problem seemed too obvious.
    Can anyone suggest and easier way to do this?
    and what is the best way to copy files in java? Copy one at a time.
    opening a bufferwriter etc? Read a block of say 64K at a time. No buffers required.
    Essectially, im
    doing a restore from multiple backup directories to
    the original directory. Please help me if you can
    take the time.If you are recovering from a backup, the most important thing is ensuring the data is correct and valid, speed is less important. (It is no good if it is fast but corrupt)
    Coping 2000 files is going to be only as fast as your drive(s) can handle. How you copy the file is less important.

  • Best way to implement a docking container

    Hi everyone,
    I need to create a docking container that behaves the same way the draggable panel system works in Flex Builder (Eclipse):
    - Dock other containers to the edges
    - Automatically layout other containers when the dragged container is docked into/out of an edge
    Is there a custom control that would enable me to do this? If not, what's the best approach to create one?
    Thanks,
    Amir

    Hi snidely_whiplash,
    snidely_whiplash wrote:
    What's the best way to implement a shared Blocking Queue that multiple JVMs can enqueue objects in and multiple JVM's can dequeue from simultaneously?
    Also, I see references on the web to com.tangosol.coherence.component.util.queue.ConcurrentQueue but I don't see it in the current API docs...
    ThanksThat class is an internal class, AFAIK.
    As for implementing a queue, you might want to look at Ashish Srivastava's ezMQ component for some ideas:
    http://ezsaid.blogspot.com/2009/01/implementing-jms-queue-on-top-of-oracle.html
    Best regards,
    Robert

Maybe you are looking for

  • XML data from BLOB to CLOB - character set conversion

    Hi All, I'm trying to solve a problem with a character set conversion in PL/SQL in the following scenario: 1. source is an XML as a BLOB variable. 2. target is an XML as a CLOB variable. 3. the problem I have is the following: - database character se

  • Pagination labels on reports

    How can i change the pagination labels. I would like to change the "next" and "previous" labels on the reports pages with the portuguese labels "Proximo" and " Anterior". Is it possible??? If so, how can i do it?? Thanks Francisco

  • Is it possible to have a right-click application?

    Is it possible to have a right-click application for the iPad? 

  • Qosmio G40-11Z - need info about Spare part

    Hello everyone. I recently bought a used Qosmio G40-11Z which was supposedly equipped with two HDDs. The two built in HDD are fine but I think that one of the HDDs "rack" is missing. Therefore, the HDD is not protected against shocks and it is quite

  • Rented a movie on my Mac but could not watch it on Apple TV

    I rented a movie from my computer and tried to watch it through 3rd generation Apple TV but could not pull it up. Home sharing is on both my computer and Apple TV.