Best way of compaing strings

Hi All
Consider i have a properties file abc.properties in which there is property key (PROPKEY1) values are delimited by semicolun
PROPKEY1 = and;in;on;by;to
In my code based on some validation i get a string whose value is some what like this
String name = "Jacob;abl;mon;sandra"
Goal is to find out whether the name(above) contains anything one value("and" or "in" or "by" or "to") from the property file
I know one way of day is iterting each of them and comparing them.
But there should be a better way to do it. Please help me on this.
Thanks in advance
Snimi

user11138361 wrote:
Goal is to find out whether the name(above) contains anything one value("and" or "in" or "by" or "to") from the property fileIt's unclear to me whether the above are values or types of check that you want to do (ie, are you comparing the entire string, or do you want to do partial checks as well?).
But there should be a better way to do it. Please help me on this.Do what EJP said. String.split() should help you create the String Sets he suggests.
You might also want to have a look at the Properties class. Extending it might be a quick way way to create what you want; alternatively, you could use it as an interim Map<String, String>.
Winston

Similar Messages

  • Please Suggest best way to pass Strings in a pipeline

    I'm working in a project in which a line passes in a pipeline kind of situation.
    The String is passed between different modules and each module adds some more data to it (or may even remove some of it).
    Which is the best way to pass the String? I think java.lang.String might not be an efficient method because the String i'll be passing will be modified many times.
    Thanx

    Yes. StringBuffer or StringBuilder you can use.
    String string = "test";
    StringBuffer sb = new StringBuffer(string);later you will add some more strings to the StringBuffer
    sb.append("Hello World");No additiional String object will be created.

  • Best way to store string resources for localization?

    My midlet has alot of string resources that I want to be able to easily customize, and I wonder what is the best way to do this using J2ME? To make the code easy to localize I would like all strings to reside in a single file (either a class file or a file system file). It doesnt seem that there is an easy way to do this (eg a "resource file" or some such). Do I just need to create a class that defines a bunch of static final String objects?
    Thx,
    Fred

    [HypnosFred],
    My midlet has alot of string resources that I want to
    be able to easily customize, and I wonder what is the
    best way to do this using J2ME? To make the code easy
    to localize I would like all strings to reside in a
    single file (either a class file or a file system
    file). It doesnt seem that there is an easy way to do
    this (eg a "resource file" or some such).Perhaps you might want to utilise the MIDP RMS record store feature i.e. javax.microedition.rms.* classes instead to store the string objects.
    Do I just need to create a class that defines a bunch of static
    final String objects?Declaring the String object variables as static final String objects upfront may help too but cannot be shared between MIDlets in a MIDlet suite though.
    Thx,
    FredHTH.
    Allen Lai
    Developer Technical Support
    SUN Microsystems
    http://www.sun.com/developers/support/

  • Best way to extract strings

    Hello,
    I need to extract the value of the strings for REQUEST_GROUP_CODE and REQUEST_GROUP_APPL_SHORT_NAME. As you can see I have to deal with whitespace differences, case differences etc. I need the values between the quotes for each one. I would expect to get ACCOUNTING and AR for the first example. I am using db version 11g r1.
    Thanks.
    WITH TEST AS
    (SELECT 'REQUEST_GROUP_CODE="ACCOUNTING" REQUEST_GROUP_APPL_SHORT_NAME="AR" TITLE="AR:AR_SRS_TITLE_ACC_RPTS"' str FROM dual
    UNION ALL
    SELECT 'REQUEST_GROUP_CODE = "PRINT_CONSINV"REQUEST_GROUP_APPL_SHORT_NAME = "AR"TITLE = "AR:AR_CONS_INV_WINDOW_TITLE"' FROM DUAL
    UNION ALL
    SELECT 'REQUEST_GROUP_CODE="JL_CO_MG_REQUEST_GROUP"                                           REQUEST_GROUP_APPL_SHORT_NAME="JL"  TITLE="JL:JL_CO_GL_MG_WINDOW_TITLE"' FROM DUAL
    UNION ALL
    SELECT 'Request_Group_Code="OE_CONC_PROGRAMS" Request_Group_Appl_Short_Name="OE" Title="OE:OE_SRS_TITLE_CONC_PROGRAMS"' FROM DUAL
    UNION ALL
    SELECT 'TITLE="INV:INV_INVENTORY_COSTS_REPORTS" USE_ORG="Y" REQUEST_GROUP_APPL_SHORT_NAME="INV" REQUEST_GROUP_CODE="INV_COST_REPORTS_GUI" PROGRAM_APPL_SHORT_NAME="BOM"' FROM DUAL
    SELECT str
      FROM TESTEdited by: Vortex13 on Jun 20, 2012 9:12 AM

    SQL> WITH test AS
      2  (SELECT 'REQUEST_GROUP_CODE="ACCOUNTING" REQUEST_GROUP_APPL_SHORT_NAME="AR" TITLE="AR:AR_SRS_TITLE_ACC_RPTS"' str FROM dual
      3  UNION ALL
      4  SELECT 'REQUEST_GROUP_CODE = "PRINT_CONSINV"REQUEST_GROUP_APPL_SHORT_NAME = "AR"TITLE = "AR:AR_CONS_INV_WINDOW_TITLE"' FROM DUAL
      5  UNION ALL
      6  SELECT 'REQUEST_GROUP_CODE="JL_CO_MG_REQUEST_GROUP" REQUEST_GROUP_APPL_SHORT_NAME="JL" TITLE="JL:JL_CO_GL_MG_WINDOW_TITLE"' FROM DUAL
      7  UNION ALL
      8  SELECT 'Request_Group_Code="OE_CONC_PROGRAMS" Request_Group_Appl_Short_Name="OE" Title="OE:OE_SRS_TITLE_CONC_PROGRAMS"' FROM DUAL
      9  )
    10  SELECT regexp_substr(str, 'REQUEST_GROUP_CODE\s*=\s*"(.*?)"', 1, 1, 'i', 1) as REQUEST_GROUP_CODE
    11       , regexp_substr(str, 'REQUEST_GROUP_APPL_SHORT_NAME\s*=\s*"(.*?)"', 1, 1, 'i', 1) as REQUEST_GROUP_APPL_SHORT_NAME
    12  FROM test
    13  ;
    REQUEST_GROUP_CODE             REQUEST_GROUP_APPL_SHORT_NAME
    ACCOUNTING                     AR
    PRINT_CONSINV                  AR
    JL_CO_MG_REQUEST_GROUP         JL
    OE_CONC_PROGRAMS               OE

  • Basic easy noob question - best way of getting string from slider value

    Hi all
    I'm using a slider in my iPhone app to allow the user to select the number of days on a scale 1 - 10 for example.
    I've got the following which isn't quite working and after battling for hours and hours to get my head around UINavigationControllers I really can't be bothered anymore. Can someone please just give me the answer
    I want to get an int value from the slider which returns a float. here's my code I have (which again, isn't working correctly).
    -(IBAction)numberofDaysSliderMoved:(id)sender {
    NSNumber *theValue = [NSNumber numberWithFloat:numberofDaysSlider.value];
    [myLabel setText:[numberFormatter stringFromNumber:theValue]];
    I know it's crap code and i've probably coded the long way round but i'm just trying to get it working and i'm new to obj-C so please bare with me.
    Regards
    Wayne

    First off - you can wrap your code here like this:
    my code here
    <-- no slash
    Here you go:
    NSNumber *sliderValue = [NSNumber numberWithFloat:numberofDaysSlider.value];
    int intValue = [sliderValue intValue];
    NSString *stringValue = [sliderValue stringValue];
    Have a look as the NSNumber docs. Lots of easy ways to create and convert numbers.
    HTH

  • What is the best way of converting everything in a result set into a string

    hello folks
    What do you think is the best way of converting everything in a resultset into a string???
    At the moment I'm using
    rs.getString(i);
    everywhere (no matter if the underlying datatype is a date or whatever..) it converts automatically evertything expect NULL into a valid string.
    Are there better (simple to use..) ways?

    I don't see a big switch construct. How about trying the following:
    Call this method from your original method by passing the resultset obtained.
    public String[] convert(ResultSet rs) {
         int col = ((ResultSetMetaData) rs.getMetaData()).getColumnCount();
         String[] record = new String[col];
         int i=0;
         while(rs.next()) {
              if(rs.wasNull()) record[i] = new String();
              else record[i] = rs.getString(i);
              i++;
         return record;
    iDriZ

  • The Best Way to Assign an Enum to the Corresponds value of a String?

    I am reading from and xml file configuration file. The data being returned is stored as a String and corresponds to a Enum value. My question is - What is the best way to assign the enum the value that corresponds to value of the string?
    public enum Names { BOB, FRED, JIM, SAM }
    String name = "FRED";   // This is the data retuned from the xml file.
    Names n =              // I want to assign n the value of Names.FREDI know I could do an "if" statement. However, this is a contrived example with only a few enum values. In the real world, this enum list could be quite large.
    I have looked into reflection, but I don't know whether there is an easier way to achieve my objective?
    Thank you for your time,
    Harold Clements

    dcminter wrote:
    But for looking up "how do I do X with a subclass of type Y", I think the API documentation should be able to answer that.I think I disagree when it's a language feature.That's definitely a point worth observing.
    By that reasoning you'd expect to populate the API docs with definitions for class (and this and super) all over the place.I think you're exaggerate, and you know it ;-)
    If those were to be mentioned in the JavaDoc, they should obviously go into the documentation of java.lang.Object only.
    I suppose you could have a "synthetics" section to the docs in much the same way that the inherited methods and fields are defined but it doesn't seem very useful.It's not useful if it's just clutter that's the same everywhere, of course.
    But in this particular case a simple "note that enum classes have a syntetic valueOf() method that does foo bar baz" in the body of the class documentation would have been a nice guesture (especially since that part is pretty small here anyway).
    And yes, I also think that the length field of arrays should find some mention in the JavaDoc. I don't know how and where, 'though.

  • Best way to split a single string containing 2 words into word1 and word2

    Whats the best way to take a string containing 2 words and split it into 2 strings ?
    eg. "red ferrari"
    string1 "red"
    string2 "ferrari"

    If your list is always going to have exactly two words, then yes.  Otherwise it depends on your requierments.

  • Best way to remove apostrophe from string when loadiing

    Hi using an insert statement to load data some apostrophe's in string .
    We need to ensure all aposrophe's removed from such strings on loading/.
    What is best way to achive ethis.
    Uisng 11.2.0.3
    Thanks

    Use replace fucntion
    Please post ur DDL and DML for the table
    For examples you can see this
    how do i replace  single quotes in a string with say  ''  or null
    select replace('ab''''''''cd','''',' ') from dual;
    CREATE TABLE my_table
         istrng  varchar2(33)
    insert into my_table
    select replace('ab''''''''cd','''',' ') from dual;Please mark your questions as answered
          user5716448     
    Handle:      user5716448 
    Status Level:      Newbie
    Registered:      Mar 16, 2010
    Total Posts:      343
    Total Questions:      131 (80 unresolved)Edited by: Rahul India on Jan 29, 2013 6:04 PM

  • Best Way to Enumerate a non-unique Array of String to Integers

    Hello,
    I am trying to find the best way to enumerate an array of strings to integers. This string array is thousands in number and contains non-unique values.
    I also don't know before run-time what those values are, so I have to dynamically determine the enumeration.
    For example a user reads in an array of colors (but we didnt know this before runtime) of "red", "green", "red", "blue", "white", "green", "black", "blue"
    I would like this to enumerate to 0, 1, 0, 2, 3, 1, 4, 2
    as zero based enumeration.
    Is there any suggested methods of doing this as efficiently on SPEED over MEMORY as possible?
    Thanks!
    Glenn

    I also don't know before run-time what those values are, so I have to dynamically determine the enumeration.Are you saying that you can't pre-define the universe of colors that a user could potentially enter? If so, how will you determine the equivalence of RED to 0, etc? That sounds suspicious, there is a finite number of colors!
    Anyway, for what it's worth, here's some code (that requires you know the color labels that could be entered.)
    enum Color
        RED(0), GREEN(1), BLUE(2), BLACK(3), WHITE(4);
        private final int colorValue;
        private Color(int colorValue)
            this.colorValue = colorValue;
        public int getColorValue()
            return colorValue;
    public class EnumTest
        public static void main(String[] args)
            System.out.println(Color.RED + " = " + Color.RED.getColorValue());
            System.out.println(Color.GREEN + " = " + Color.GREEN.getColorValue());
            System.out.println(Color.BLUE + " = " + Color.BLUE.getColorValue());
            System.out.println(Color.BLACK + " = " + Color.BLACK.getColorValue());
            System.out.println(Color.WHITE + " = " + Color.WHITE.getColorValue());
    }

  • Best way to remove unwanted signs from string

    Which is the best way to purify a string from possible dangerous signs? I want to remove all characters that is not a-z or 0-9? how would I go about?

    read the string character by character, and check to
    see if they're characters you want to remove or not,
    by comparing them to the ascii values of characters
    you permit. I've used this before, but I can't
    remember what exactly it permits, and I'm too lazy to
    look up the ascii table :) But this sort of thing
    works.
    int c = in.read();
    while(c!=-1){
    if((c<33)||(c<58&&c>44)){
         out.write(c);
    I thought about that too. But the values in the ASCII table... arn't they a little volatile to use? I mean, will my application work on other systems or systems with other languages?

  • Remove at "space" of a string? How the best way to remove it???

    I get a string
    e.g:
    string s="a b c   d     s  c s g w".
    I want as results:
    e.g:
    string s="a b c d s c s g w".
    How the best way to remove it??? I don't want that (value.Split("     ","")).

    You could use regex as follows:
    System.Text.RegularExpressions.Regex.Replace(yourString, " +", " ")

  • Best Way to Check for same Word in string?

    If I have an array of words, would the best way to check for the same word be to use 2 for loops?

    Huh?
    Sounds like homework...
    What is a word? Presumably a String.
    For equality of Strings you use...
        String s1 = ....
        String s2 =....
        if (s1 == s2) { equal depending on null case
        else if ((s1 != null) && (s1.equals(s2))) { equal }
    For the case of checking one array to another....
          while items in array1
                 get itema from array1
                      while items in array2
                           get itemb array2
                                  is itemb equal (see above) to itema
                                         yes - then do something

  • Best way to look for next char in String that is NOT "-" or " " or ","?

    I have a long String that is sent to me and needs to be parsed. Normally I can figure the end of the line by a line break, but sometimes the line break is lost only after the second line. This second line contains the characters:
    These characters can all appear any number of times. I will know I'm at the end of the line when I hit a character that is not one of those three. What is the best way to look for this? Is there an already set method in the Java API?
    Thanks for all the help!

    There are solutions using regular expression, eg; you can split string once a time using minus char, whitespace or comma:
    String tokens[] = anyString.split("\\-|\\x20|,");
    More sophisticated expressions could be done to achieve results:
    String re = "^(.+)(\\-|\\x20|,)(.)(.*)$";
    Matcher m = Pattern.compile(re).matcher(anyString);
    if (m.matches()) {
    String
    before = m.group(1),
    delimiter = m.group(2),
    firstCharAfterDelimiter = m.group(3),
    suffix = m.group(4);
    Regards.

  • Best way to break down a string?

    Hi.
    I am wondering, what is the best way to get all the substrings with a patten from a string.
    Here is an example.
    String str = "|hello|123456|a,b,c,d,e,|"
    i want to get all the substrings between 2 consecutive "|" symbols.
    hello
    123456
    a,b,c,d,e,
    is there a build in method to achieve it? Read it char by char is the only way?
    what do you think is most efficient way of doing it?

    Hi.
    I am wondering, what is the best way to get all the
    substrings with a patten from a string.
    Here is an example.
    String str = "|hello|123456|a,b,c,d,e,|"
    i want to get all the substrings between 2
    consecutive "|" symbols.
    hello
    123456
    a,b,c,d,e,
    is there a build in method to achieve it? Read it
    char by char is the only way?
    what do you think is most efficient way of doing it?i would use the substring command and look for the index's of the characters you wan't it saves a lot of space compared to the charAt command.. something kinda like this(you prob need to fix it up some)
    )String str = "|hello|123456|a,b,c,d,e,|"
    int index = 0
    while (front < str.LastindexOf("|")
          frontindex = str.indexOf("|",front)
          backindex = str.indexOf("|",front+1)
          newstr[index] = str.substring (front, back)
    index++
    }

Maybe you are looking for

  • Send KeyEvents to a TextField

    Hi, I have a small problem with sending Key events from code to a JTextField component. I use the EventQueue's postEvent method to post the event: Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(event) It seems, that the listeners associa

  • Install cf8 standard edition with remote apache?

    I am interested in installing cf8 standard edition on a stand alone server on a windows (win2003 standard 64 bit) box. An Apache web server (centOS 5) and a mysql will be another two separate servers. So, I am wondering if this infrastructure is OK?

  • What is the best way to learn Mac OS X 10.7 Lion in depth?

    What is the best way to learn Mac OS X 10.7 Lion in depth? I have updated to lion a few months ago, found my way around just by playing with it, but now I would like to get serious and learn pretty much all it can do. But wondering if I should get on

  • Messages menu status does not match Buddy List window

    Using Messages in Yosemite, the status of my logged-in buddies listed in the menu bar does not match the status of my buddies in the Buddies window. I have buddies listed in the window that are not in the menu bar and vice versa. It seems that the me

  • LMS 4.2, Duplicate event in DFM

              Hi all !! Recently we have migrated to LMS 4.2.3 before 1 month. In 4.2 I observed for any operationally down interface, duplicate events are appearing with new time stamp periodically. As per my knowledge an "Operationally down" event reap