Delimeter Between Strings

I am going to provide a long string as a parameter to a method. This long string consists of a number of Strings (the number is a variable) separated by delimeters; for example, "aa, bbbbb, ccc, ddddddd".
This method is supposed to return the length of the longest string in this comma separated list:
public int longestLength(String longString) { ...  return longest; }
We can determine the length of a String using the length() method. And I am thinking to use the split() method and trim() method to get "aa", "bbbbb", "ccc", "ddddddd". In this case, the value 7 should be returned by the method.
However, I still need ideas about how to implement this method. Can anybody help? Thank you.

1) first try it yourself: you have nothing to lose by experimenting, and you truly should be able to get an answer on your own knowing what you know.
2) come back with code if this doesn't work.
The bottom line: you learn more if you do as much as possible on your own.

Similar Messages

  • What is the difference between string != null and null !=string ?

    Hi,
    what is the difference between string != null and null != string ?
    which is the best option ?
    Thanks
    user8729783

    Like you've presented it, nothing.  There is no difference and neither is the "better option".

  • What is the difference between String Constant and Empty String Constant

    What is the difference between string constant which does not contain any value and the Empty string constant?
    While testing a VI which contain a normal string constant in VI analyzer, it gives error to change string constant with the empty string constant?
    Please Reply
    prabhakant
    Regards
    Prabhakant Patil

    Readability.
    Functionally, they are the same. From a coding standpoint, the Empty String Constant is unambiguous.
    It is empty and will always be; good for initialization. Also, because you can not type a value into and Empty String Constant, someone would need to conciously replace it to set a 'default' value that is something other than NULL.
    Now is the right time to use %^<%Y-%m-%dT%H:%M:%S%3uZ>T
    If you don't hate time zones, you're not a real programmer.
    "You are what you don't automate"
    Inplaceness is synonymous with insidiousness

  • Difference between String and final String

    Hi friends,
    This is Ramana. Can u suggest me in this Question
    What is the difference between String and final String? Means
    String str="hai";
    final String str="hai";
    Regards,
    Ramana.

    *******REPEAT POST***********
    We already answered your question why post in a different section?
    http://forum.java.sun.com/thread.jspa?threadID=5201549

  • Adding white spaces between strings during concatenation in JSTL

    Please provide a way to add white space between strings during concatenation in JSTL.
    I tried the following.
    eg:
    <c:set var="even_odd" value="odd">
    <c:out value="first ${even_odd}"/>
    I want the output string as "first odd ".
    Moreover i am using the above value for generating the class attribute of a row of a table like
    <tr class=<c:out value="first ${even_odd}"/>>
    while printing the value of <c:out value="first ${even_odd}"/> in the page,i am getting correctly as i needed as "first odd".
    But while taking the code of the page while rendering by the browser, it is showing like
    <tr class="first" odd="">
    I think the white space is the problem.
    Please provide any solution or hint.

    <tr class=<c:out value="first ${even_odd}"/>><tr class="first ${even_odd}">

  • What Are the Differences Between String and StringBuffer?

    Both String and StringBuffer are final classes. StringBuffer grows in size dynamically. Could people help to detail other differences between String and StringBuffer?

    String is immutable. In other words, once it is made, the contents of that instance of String cannot be changed (easily). The size and characters cannot be changed, and code can take advantage of this fact to optimize space. Also, once you have a reference to a string, you do not need to worry about it changing at all, so you can eliminate constant tests to verify things such as size in another class that may want to hold onto the string.
    StringBuffer, as you noticed, can change dynamically. While this provides flexibility, it cannot be optimized and assumptions cannot be made as with strings. If a class holds a reference to a StringBuffer that it does not own, there is a possibility that it may change things such as size when the class tries to use it later. StringBuffer is also less efficient in handling space then an equivalent String. The character array to hold a String is exactly the length to hold all the characters. StringBuffer, on the other hand, adds a 16 character buffer of array space for possible expansions. Also, the size of the internal array doubles when its internal capacity is exceeded. So, unless you explicitly maintain the size, a StringBuffer will take up more memory then an equivalent String, and if your program needs thousands of instances of Strings (which is not uncommon), that space can add up.
    I hope this helps clarify some things for you.
    -JBoeing

  • What's the difference between String() - as String - toString();

    Hello,
    I'm wondering what's the difference between this 3 ways of getting around.

    There is a great difference between String(), as String and toString() methods.
    String(param) -- the more general and safe method.
    Returns "null" (string!) if param is null;
    Returns result of param.toString() method if it is defined in class;
    Returns string representation of the param (returns "[object Object]" if param is Object);
    param asString --
    Returns string if param is a type of String;
    Returns null otherway (if param is custom class, int or other type);
    param.toString() -- call of toString() member function
    throws an exception if param is null;
    compile-time error if toString() method is not defined in param (if your custom class do not have or inherits this function);
    returns result of toString() function
    Exists also ""+param and param+"" ways. They are similar to ""+String(param) and String(param)+""
    Pay attention:
    var ss:String = null;
    trace(String(ss)==(ss as String)); // Returns false as "null" not equal to null

  • Difference between String=""; and String =null

    I want to know the difference especially the ADVANTAGE between the following-
    1. String s="";
    String s="ABC"
    and
    String s;
    String s="ABC";
    or String s=null;
    String s="ABC";
    2. Object anyObject;
    anyObject-new Object();
    and
    Object anyObject=null;
    anyObject=new Object();

    Tanvir007 wrote:
    I want to know the difference especially the ADVANTAGE between the following-
    1. String s="";s points to the empty string--the String object containing no characters.
    String s="ABC"s points to the String object containing the characters "ABC"
    String s; Declares String reference varialbe s. Doesn't not assign it any value. If it's a local variable, it won't have a value until you explicitly assign it. If it's a member variable, it will be given the value null when the enclosing object is created.
    String s="ABC";Already covered above.
    or String s=null;s does not point to any object.
    String s="ABC";???
    You've already asked this twice.
    Are you talking about doing
    String s = null;
    String s = "ABC";right after each other?
    You can't do that. You can only declare a variable once.
    If you mean
    String s = null;
    s = "ABC";It just does what I described above, one after the other.
    2. Object anyObject;
    anyObject-new Object();
    and
    Object anyObject=null;
    anyObject=new Object();As above: In the first case, its value is undefined until the new Object line if it's a local, or it's null if it's a member.
    As for which is better, it depends what you're doing.

  • Query on conversion between String to Enum type

    Hi All,
    I would like to get advice on how to convert between char and Enum type. Below is an example of generating unique random alphabet letters before converting them back to their corresponding letters that belonged to enum type called definition.Alphabet, which is part of a global project used by other applications:
    package definition;
    public enum Alphabet
    A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S,
    T, U, V, W, X, Y, Z
    public StringBuffer uniqueRandomAlphabet()
    String currentAlphabet="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    StringBuffer randomAlphabetSB = new StringBuffer();
    for (int numberOfAlphabet=26; numberOfAlphabet>0; numberOfAlphabet--)
    int character=(int)(Math.random()* numberOfAlphabet);
    String characterPicked = currentAlphabet.substring(character, character+1);
    // System.out.println(characterPicked);
    randomAlphabetSB.append(characterPicked);
    StringBuffer remainingAlphabet = new StringBuffer( currentAlphabet.length() );
    remainingAlphabet.setLength( currentAlphabet.length() );
    int current = 0;
    for (int currentAlphabetIndex = 0; currentAlphabetIndex < currentAlphabet.length(); currentAlphabetIndex++)
    char cur = currentAlphabet.charAt(currentAlphabetIndex);
    if (cur != characterPicked.charAt(0))
    remainingAlphabet.setCharAt( current++, cur );
    currentAlphabet = remainingAlphabet.toString();
    return randomAlphabetSB;
    // System.out.println(randomAlphabetSB);
    I got the following compilation error when trying to pass (Alphabet) StringBuffer[0] to a method that expects Alphabet.A type:
    inconvertible types
    required: definition.Alphabet
    found: char
    Any ideas on how to get around this. An alternative solution is to have a huge switch statement to assemble Alphabet type into an ArrayList<Alphabet>() but wondering whether there is a more shorter direct conversion path.
    I am using JDK1.6.0_17, Netbeans 6.7 on Windows XP.
    Thanks a lot,
    Jack

    I would like to get advice on how to convert between char and Enum type. Below is an example of generating unique random alphabet lettersIf I understand well, you may be interested in method shuffle(...) in class java.util.Collections, which randomly reorders a list.
    before converting them back to their corresponding letters that belonged to enum type called definition.AlphabetIf I understand well, you may be interested in the built-in method Alphabet.valueOf(...) which will return the appropriate instance by name (you'll probably have no problem to build a valid String name from a lowercase char).

  • How to make comparison between strings using Labview

    helo, i want to know, how to make comparison between array of string.?
    the transmitter have send the assign text such as
    A hello            Bhye  Cbye

    Hi Syanitaa,
    You actually only need to post the question once. 
    Multiple duplication. Please refer to this thread.

  • Adding image between string

    How to add a image between two string.
    example
    Test string one <IMG> testing string two

    An empty loop to wait for something is to avoid in all languages! At worst, put a sleep call in the loop. But a better idiom for JavaFX would be:
    function ChangeImage(image: Image): Void
        fadeOut.action = function()
            selectedImage = Image
                url: fileURL;
                height: 400, preserveRatio: true
                backgroundLoading: true
            var progress = bind selectedImage.progress on replace
                if (progress == 100)
                    fadeIn.playFromStart();
        fadeOut.playFromStart();
    }(untested)
    First, I create the Image when needed, to start the background loading. Or maybe the loading is very long and you prefer to start earlier, so your version is fine in this case.
    Second, I do what I described, binding to the progress variable of selectedImage, and watching the updates. And when we reach the wanted value, we start the second animation.

  • Line gap between string

    Hi,
    I want to concatenate two strings in a single one, and there shoule be gap of two lines between those two strings.
    example I want to concatenate string1 and string2 in string3, then after concatenate the string3 should have value as shown below:
    string1
    string2
    I have tried all the attributes of class CL_ABAP_CHAR_UTILITIES but it doesnt helped.
    Kindly suggest.
    Regards,
    Neerup

    Look at the code:
    DATA: lv_string1  TYPE string VALUE 'string1',
          lv_string2  TYPE string VALUE 'string2',
          lv_string3  TYPE string.
    CONCATENATE lv_string1
                cl_abap_char_utilities=>cr_lf
                cl_abap_char_utilities=>cr_lf cl_abap_char_utilities=>cr_lf
                lv_string2
    INTO lv_string3.
    WRITE lv_string3.
    When you now download this list (save to local file) and open it in notepad, you will notice that it has three empty lines between the first and the second string.
    The code is ok, however, you're requirement might not be clear to me.

  • Fastest way to access data between String and char[]

    Hi all,
    I've been programming a small String generator and was curious about the best and fastest way to do so.
    I've done it in two ways and now hope you can tell me if there is a "more java version" or fastest way between those two or if I'm totally wrong as some classe in the API already does that.
    Here are the codes:
    version 1:
            //describe the alphabet
         String alphabet = "abcdefghijklmnopqrstuvwxyz";
         //The "modifiable String"
         StringBuffer stringBuffer = new StringBuffer();
         //Just put the temporary int declaration outside the loop for performance reasons
         int generatedNumber;
         //Just do a "for" loop to get one letter and add it the String
         //Let's say we need a 8 letters word to be generated
         for (int i=0; i < 8; i++)
             generatedNumber = (int)(Math.random() * 26);
             stringBuffer.append(alphabet.charAt(generatedNumber));
         System.out.println(stringBuffer.toString());
         stringBuffer =null;version 2:
            //describe the alphabet
         char[] alphabetArray = {'a', 'b', 'c', 'd', 'e', 'f',
                        'g', 'h', 'i', 'j', 'k', 'l',
                        'm', 'n', 'o', 'p', 'q', 'r',
                        's', 't', 'u', 'v', 'w', 'x',
                        'y', 'z'}
         //The "modifiable String"
         StringBuffer stringBuffer = new StringBuffer();
         //Just put the temporary int declaration outside the loop for performance reasons
         int generatedNumber;
         //Just do a "for" loop to get one letter and add it the String
         //Let's say we need a 8 letters word to be generated
         for (int i=0; i < 8; i++)
             generatedNumber = (int)(Math.random() * 26);
             stringBuffer.append(alphabetArray[generatedNumber]);
         System.out.println(stringBuffer.toString());
         stringBuffer =null;Basically, the question is, what is the safest, fastest and more "to the rules" way to access a char in a sequence?
    Thanks in advance.
    Edited by: airchtit on Jan 22, 2008 6:02 AM

    paul.miner wrote:
    Better, use a char[] instead of a StringBuffer/StringBuilder, since you seem to know the size of the array in advance.
    Although I imagine making "alphabet" a char[] has slightly less overhead than making it a String
    1. It's a lot clearer to write it as a String.
    2. You can just call toCharArray() on the String to get a char[], instead of writing out each char individually.
    3. Or if you're going to be using a plain alphabet, just use (randomNumber + 'a')
    And use Random.nextInt()Hello and thx for the answers,
    I know I shouldn't put constants in my code, it was just a piece of code done in 1 minute to help a colleague.
    Even if it was just a one minute piece of code, I was wondering about the performance problem on large scale calculating, I mean something like a 25 characters word for billions of customers but anyway, once again, the impact should be minimal.
    By the way, I didn't know the Random Class (shame on me, I still don't know the whole API) and, I don't understand why I should be using this one more than the Random.Math which is static and thus take a few less memory and is easier to call.
    Is it because of the repartition factor?
    According to the API, the Random.Math gives (almost) a uniform distribution whether the Random.nextInt() gives a "more random" int.
    I

  • Preserve spaces between strings...

    Hi everyone,
    I an trying to extract some data to a flat file in a format that each column has start and end positions.
    I am trying to pad some "spaces" after each column to get my requirement.My code is not preserving the
    spaces between each string.
    This is what i have..
    But the strange thing i found is..i ran the following code
    declare
    final_str varchar2(100);
    begin
    final_str := rpad('12',4)||rpad('12',4);
    insert into test(col1) values (final_str);
    end;and it is preserving the spaces .
    Is there anything wrong with my code.I need to preserve the spaces after each string.
    Please help me to solve this issue..
    Thanks

    Hi Phani,
    If you use chars instead of varchar2's you keep fixed lengths.
    F.i.:
    SQL> declare
      2    a varchar2(50);
      3    b char(50);
      4  begin
      5 
      6    for rec in ( select level*100 l from dual connect by level <= 5)
      7    loop
      8      a:=rec.l;
      9      b:=rec.l;
    10      dbms_output.put_line('>'||a ||'< (lenghth a = '||length(a)||')');
    11      dbms_output.put_line('>'||b ||'< (lenghth b = '||length(b)||')');
    12    end loop;
    13  end;
    14  /
    100< (lenghth a = 3)
    100 < (lenghth b = 50)
    200< (lenghth a = 3)
    200 < (lenghth b = 50)
    300< (lenghth a = 3)
    300 < (lenghth b = 50)
    400< (lenghth a = 3)
    400 < (lenghth b = 50)
    500< (lenghth a = 3)
    500 < (lenghth b = 50)
    PL/SQL procedure successfully completed.

  • Javascript + space between string

    HI,
    I have a drop box on my jsp page, I am selecting multiple values and passing them to serlvet.Onclcick event of my button I am callin JS function, and I am seperating selected values by comma in a string.
    But if string contains space inbetween it takes only first half of (string before space)
    For example, if selected names are 'AAA BBB', 'ABC', 'CCC'
    It takes: AAA,ABC,CCC
    it doesn't take anything after space.
    Could anyone please help with sample code, I will really appreciate it?
    Thanks

    Like I mentioned in the other topic, it's probably because your value isn't between double quotes.
    In the code I've given below, you'll get alerts saying 'First Value', 'Second' and 'Third Value'. For the second one, the 'Value' word is missing since it isn't enclosed in double quotes.
    <html>
    <script>
    function getDropDownValues( )
         dropDownBox = document.getElementById('dropdownexample');
         for ( i = 0; i < dropDownBox.options.length; i++ )
              alert(dropDownBox.options.value);
    </script>
    <body>
    <select id="dropdownexample">
    <option value="First Value">1</option>
    <option value=Second Value>2</option>
    <option value="Third Value">3</option>
    </select>
    <input type="button" value="Show Me The Values" onclick="getDropDownValues();" />
    </body>
    </html>
    Oh, and JavaScript doesn't have anything to do with Java. And these are Java forums :)

Maybe you are looking for

  • Passing columns with UTF8 code on fx formula

    Hi! I'm using obiee 11.1.1.5.0 I have an analysis that contains HTML Code, some code is passed to a URL, so I need to convert diferent symbols like ó to %C3%B3 etc. I have a lot of symbols...so I can't use REPLACE function in my formula column of my

  • Phone interference when Broadband connected

    Can anyone help?  My phone works perfectly when internet isn't connected (its not wireless) but when it is, there's so much noise on the line its unusable.  Can someone advise? Thanks

  • Unused reports in OBIEE

    Hi, Is there any option in OBI to check what all the reports accessed by the users and the reports that were not accesses. I am basically interested in seeing the list of users who have accessed the reports and if so,what reports they have accessed.A

  • Equium A110-276: multimedia buttons do not work with Vista

    How to reinstall the software of the multimedia buttons at the right side of the laptop in Windows Vista? becuase when I install windows vista the buttons doesn't work anymore.. multimdia buttons: the WMPlayer, play/pause, stop, next and previous but

  • Page-name change disables Quicktime file. Please help.

    I've been using a text editor to go into the html and change the name which appears at the top of my home page. So far so good. However, I recently added a Quicktime movie to the home page. I've discovered that if I now change the page name, the movi