Difference in String joining

String m="Hello"
Is there any difference between
m=m+" Java";
and
m=m.concat(" Java");There must be some difference I guess, but not sure where.
Can anyone explain please?

Another interview question?
Adding strings with + gets compiled into instantiations and invocations of StringBuffer or StringBuilder, invoking append() on it, and then calling toString on it. That is, unless the stuff you're adding is all immutable at compile time, in which case the concatenation happens at compile time and the class just has a big string.
.concat(), I presume, creates a new String object right there and doesn't get transmogrified into anything else at compile time.
As such, if you're doing a lot of string concatenations, or if the concatenations are built with immutable values, it's more efficient to use +. On the other hand if you're doing a single concatenation using a variable, .concat() is probably more efficient.
But these are just educated guesses. Try experimenting with both, disassembling the class files with javap to see what happened, looking at the source code, etc.

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

  • Xmltable fn:string-join

    create table emp (doc XMLtype);
    insert into emp values(
    xmltype('<dept bldg="114">
         <employee id="903">
              <name>
                   <first>Mary</first>
                   <last>Jones</last>
              </name>
              <office>415</office>
              <phone>905-403-6112</phone>
              <phone>647-504-4546</phone>
              <salary currency="USD">64000</salary>
         </employee>
    </dept>'));
    I need the output to be
    Mary Jones 905-403-6112,647-504-4546
    I tried
    SELECT X.* FROM emp ,
    XMLTABLE ('$d/dept/employee' passing doc as "d"
         COLUMNS
         first VARCHAR2(25) PATH 'name/first',
         last VARCHAR2(25) PATH 'name/last',
         phone VARCHAR2(100) PATH 'fn:string-join(phone/text(),",")'
    ) AS X
    and received error
    ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00601: Invalid token in: '/*/fn:string-join(phone/text(),",")'
    please advise. thanks.

    SCOTT@soti_10> with emp as(
      2    select xmltype(
      3           '
      4            <dept>
      5              <employee id="901">
      6                <name>
      7                  <first>John</first>
      8                  <last>Doe</last>
      9                </name>
    10              </employee>
    11              <employee id="902">
    12                <name>
    13                  <first>Peter</first>
    14                  <last>Pan</last>
    15                </name>
    16                <phone>905-416-5004</phone>
    17              </employee>
    18              <employee id="903">
    19                <name>
    20                  <first>Mary</first>
    21                  <last>Jones</last>
    22                </name>
    23                <phone>905-403-6112</phone>
    24                <phone>647-504-4546</phone>
    25              </employee>
    26            </dept>
    27           '
    28           ) as doc
    29    from dual
    30  )
    31  SELECT X.*
    32  FROM emp ,
    33    XMLTABLE (
    34      'for $e in $d/dept/employee,
    35           (: $pi - index of the current phone element.
    36              If there is no phone elements at all then $pi = 0, otherwise $pi > 0 :)
    37           $pi in (0 to fn:count($e/phone))[. > 0 or fn:last() = 1]
    38       return <e>
    39                {$e/name}
    40                {$e/phone[$pi]}
    41              </e>'
    42      passing doc as "d"
    43      COLUMNS first VARCHAR2(25) PATH 'name/first',
    44              last VARCHAR2(25) PATH 'name/last',
    45              phone VARCHAR2(100) PATH 'phone'
    46    ) AS X
    47  ;
    FIRST                     LAST                      PHONE
    John                      Doe
    Peter                     Pan                       905-416-5004
    Mary                      Jones                     905-403-6112
    Mary                      Jones                     647-504-4546Regards,
    Dima

  • Difference between inner join and outer join

    1.Difference between inner join and outer join
    2.wht is the difference in using hide and get crusor value in interactive.
    3. Using join is better or views in writting program . Which is better.

    Table 1                      Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
        Inner Join
        |--||||||||--|
        | A  | B  | C  | D  | D  | E  | F  | G  | H  |
        |--||||||||--|
        | a1 | b1 | c1 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a2 | b2 | c2 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a4 | b4 | c4 | 3  | 3  | e2 | f2 | g2 | h2 |
        |--||||||||--|
    Example
    Output a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE   LIKE SFLIGHT-FLDATE,
          CARRID LIKE SFLIGHT-CARRID,
          CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
        INTO (CARRID, CONNID, DATE)
        FROM SFLIGHT AS F INNER JOIN SPFLI AS P
               ON FCARRID = PCARRID AND
                  FCONNID = PCONNID
        WHERE P~CITYFROM = 'FRANKFURT'
          AND P~CITYTO   = 'NEW YORK'
          AND F~FLDATE BETWEEN '20010910' AND '20010920'
          AND FSEATSOCC < FSEATSMAX.
      WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    If there are columns with the same name in both tables, you must distinguish between them by prefixing the field descriptor with the table name or a table alias.
    Note
    In order to determine the result of a SELECT command where the FROM clause contains a join, the database system first creates a temporary table containing the lines that meet the ON condition. The WHERE condition is then applied to the temporary table. It does not matter in an inner join whether the condition is in the ON or WHEREclause. The following example returns the same solution as the previous one.
    Example
    Output of a list of all flights from Frankfurt to New York between September 10th and 20th, 2001 that are not sold out:
    DATA: DATE   LIKE SFLIGHT-FLDATE,
          CARRID LIKE SFLIGHT-CARRID,
          CONNID LIKE SFLIGHT-CONNID.
    SELECT FCARRID FCONNID F~FLDATE
        INTO (CARRID, CONNID, DATE)
        FROM SFLIGHT AS F INNER JOIN SPFLI AS P
               ON FCARRID = PCARRID
        WHERE FCONNID = PCONNID
          AND P~CITYFROM = 'FRANKFURT'
          AND P~CITYTO   = 'NEW YORK'
          AND F~FLDATE BETWEEN '20010910' AND '20010920'
          AND FSEATSOCC < FSEATSMAX.
      WRITE: / DATE, CARRID, CONNID.
    ENDSELECT.
    Note
    Since not all of the database systems supported by SAP use the standard syntax for ON conditions, the syntax has been restricted. It only allows those joins that produce the same results on all of the supported database systems:
    Only a table or view may appear to the right of the JOIN operator, not another join expression.
    Only AND is possible in the ON condition as a logical operator.
    Each comparison in the ON condition must contain a field from the right-hand table.
    If an outer join occurs in the FROM clause, all the ON conditions must contain at least one "real" JOIN condition (a condition that contains a field from tabref1 amd a field from tabref2.
    Note
    In some cases, '*' may be specified in the SELECT clause, and an internal table or work area is entered into the INTO clause (instead of a list of fields). If so, the fields are written to the target area from left to right in the order in which the tables appear in the FROM clause, according to the structure of each table work area. There can then be gaps between table work areas if you use an Alignment Request. For this reason, you should define the target work area with reference to the types of the database tables, not simply by counting the total number of fields. For an example, see below:
    Variant 3
    ... FROM tabref1 LEFT [OUTER] JOIN tabref2 ON cond
    Effect
    Selects the data from the transparent database tables and/or views specified in tabref1 and tabref2. tabref1 und tabref2 both have either the same form as in variant 1 or are themselves join expressions. The keyword OUTER can be omitted. The database tables or views specified in tabref1 and tabref2 must be recognized by the ABAP-Dictionary.
    In order to determine the result of a SELECT command where the FROM clause contains a left outer join, the database system creates a temporary table containing the lines that meet the ON condition. The remaining fields from the left-hand table (tabref1) are then added to this table, and their corresponding fields from the right-hand table are filled with ZERO values. The system then applies the WHERE condition to the table.
    Left outer join between table 1 and table 2 where column D in both tables set the join condition:
    Table 1                      Table 2
    A
    B
    C
    D
    D
    E
    F
    G
    H
    a1
    b1
    c1
    1
    1
    e1
    f1
    g1
    h1
    a2
    b2
    c2
    1
    3
    e2
    f2
    g2
    h2
    a3
    b3
    c3
    2
    4
    e3
    f3
    g3
    h3
    a4
    b4
    c4
    3
    |--|||--|
        Left Outer Join
        |--||||||||--|
        | A  | B  | C  | D  | D  | E  | F  | G  | H  |
        |--||||||||--|
        | a1 | b1 | c1 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a2 | b2 | c2 | 1  | 1  | e1 | f1 | g1 | h1 |
        | a3 | b3 | c3 | 2  |NULL|NULL|NULL|NULL|NULL|
        | a4 | b4 | c4 | 3  | 3  | e2 | f2 | g2 | h2 |
        |--||||||||--|
    Regards
    Prabhu

  • Difference between oracle join syntaxes and ANSI join syntaxes

    What is difference between oracle join syntaxes and ANSI join syntaxes ?
    why oracle is having different syntaxes for joins than ANSI syntaxes ?
    Also Join syntaxes are different in some oracle vesrions ?

    BluShadow wrote:
    3360 wrote:
    Yes it is. The Oracle database wasn't initially designed to be ANSI compliant. As you correctly state the ANSI standards weren't around when it was initially designed, so the statement is perfectly correct. ;)Ok, in one sense it may be correct but it is a completely misleading statement. Not sure why you think it's misleading.Because there was no ANSI standard, so making it sound like a design choice The Oracle database wasn't initially designed to be ANSI compliant. would suggest to most readers that there was a standard to be compliant to.
    Like saying Ford originally did not design their cars to incorporate safety features such as ABS, seat belts and air bags.
    The OP asked "why oracle is having different syntaxes for joins than ANSI syntaxes ?" and the answer is that Oracle wasn't initially designed with ANSI compliance, so it has it's old non-ANSI syntax,As shown above, the old syntax was ANSI compliant at the time and to call it non-ANSI is either incorrect or misleading dependent on your point of view.
    and since ANSI syntax became the standard it now supports that. And since ANSI switched to a new standard, Oracle had to implement the new standard as well as the previous ANSI standard would be more accurate in my opinion.
    Nothing misleading as far as I'm aware in that.I find the whole discussion about ANSI and Oracle's supposed non-compliance, reads like it was Oracle's choice to deviate from the standards, when it was ANSI's bullheaded decisions to pointlessly change standards that left Oracle and other vendors out of compliance, and that was a decision made solely by ANSI.
    This is probably the reason ANSI no longer produces SQL standards, the endless syntax fiddling would eventually have made forward left under outer joins a reality.
    {message:id=1785128}

  • 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

  • Xquery concat / string-join / replace

    Hi, I am a newbie on Xquery.
    And I need some help on a problem I been having.
    My in data is three digit numbers (ex. "123" "321" "213" etc). And I need to separate this with a comma ",". The problem is how do I do this if the input is only one item?, and second how do I not
    put a "," on the last item?
    I have tried a for-loop where a concat my string with with "," but the result is "123, 321, 213,". I do not want the last comma. And the spaces is not real whitespaces. I don't know where this comes from, the can not be removed or be used to
    replace them with a comma (which would be the simplest way to solve my problem) but doesn't work.
    for $Something in $Something/ns0:Something
    return
    fn:concat(data($Something)," ",",").
    This returns "123, 321, 213,".

    I have solved it.
    string-join((     data($Something/SomethingElse)),",")
    Thanks.

  • Strange string-join behaviour

    HI,
    I tested the following query in 10gr2 and 11gr2
    SELECT XMLQuery('string-join("a","b")'
                    returning content) as output
      FROM DUAL;
    Result => a and  NOT ab.
    Any idea why this result?
    Thanks,
    Henk

    Some doc reading might help : fn:string-join()
    The function concatenates a sequence of strings (first arg) into a single string using the second arg as separator.
    In your example, the sequence consists in a single item so the result is the item itself.
    Are you looking for fn:concat() ?
    SQL> select xmlquery('concat("a","b")' returning content)
      2  from dual;
    XMLQUERY('CONCAT("A","B")'RETU
    ab

  • Difference between physical join and logical join

    Hi Gurus,
    Can anyone tell me what is the difference between physical join and logical join
    Thanks,
    Chandra

    Hi,
    A physical join is at the physical layer and defines the join between two physical tables. Logical joins live at the BMM (logical) layer and define a join between two logical tables.
    The important differentiation is that at the BMM layer you do not tell the OBIEE server how to do the join, you just tell it that there is a relationship between these two logical entities. When the server comes to this logical join it will use the information in the physical joins and decides how the two logical tables are joined together.
    In BMM you use complex joins to establish which logical tables are joined which another, the OBI EE server will go to the physical level to search the physical join to make the query. You can also use physical joins in the BMM to override the join in the physical layer but only in very specific conditions.
    If you also set complex join in the physical layer OBI EE won't be able to construct the physical query.
    Hope this answers your question.
    Award points if helpful.
    Thanks,
    -Amith.

  • 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.

  • Difference in String declaration

    Hello All,
    Can any one please tell me whats the difference between following String declarations:
    a) String str = "abc";
    b) String str = new String( "abc" );
    Also please tell me which one is correct way of declaration and in which sence.
    Thanks in advance..........

    both are different
    the first one creates one String object and one reference variable. The second one creates two string objects, one in non-pool memory and the reference variable will refer to it., the second object is the literal that will be placed in the pool.

  • Differences between left join in oracle8 style and oracle10g style

    Hi,
    I need some help to figure out what impact can be, on a product, the migration of query left join syntax from the Oracle8 one to the Oracle10g:
    we have a product that uses Hibernate configured to use the Oracle8 dialect to perform queries which uses the (+) sintax to perform outer join query, and we encountered a bug in that dialect that is forcing us to move on the Oracle10g dialect which uses the ANSI 92 style to perform outer join queries.
    Someone know if there are differences/bugs/incompatibilities for outer join query written using the ANSI 92 style instead the Oracle8 style like DB functions (like NVL(), DECODE(), and so on) that work in a different way using a style instead the other?
    Thanks.
    Luca.

    luca.depetrillo wrote:
    Hi,
    I need some help to figure out what impact can be, on a product, the migration of query left join syntax from the Oracle8 one to the Oracle10g:
    we have a product that uses Hibernate configured to use the Oracle8 dialect to perform queries which uses the (+) sintax to perform outer join query, and we encountered a bug in that dialect that is forcing us to move on the Oracle10g dialect which uses the ANSI 92 style to perform outer join queries.
    Someone know if there are differences/bugs/incompatibilities for outer join query written using the ANSI 92 style instead the Oracle8 style like DB functions (like NVL(), DECODE(), and so on) that work in a different way using a style instead the other?
    Thanks.
    Luca.In earlier versions of 10g (i.e. 10.1.?.?) there was a few bugs in the ANSI syntax joins on SQL, but they seemed to have sorted most of those out for 10.2.?.? onwards.
    Essentially there will be no real adverse effects in using ANSI syntax, and it shouldn't stop your other functions working.
    ANSI syntax also gives you the advantage that you can outer join to more than one table which you can't do in Oracle syntax outer joins.
    Edited by: BluShadow on Nov 18, 2008 2:06 PM
    prevented stupid forum formatting

Maybe you are looking for

  • MBP appears to start up in safe boot!?

    I have a MBP running 10.6.8 At start up it appears to be starting in Safe Boot without me wanting it to. ie grey screen, apple logo, progress bar in darker grey. This takes about 10 mins. When it has completed this is is not actually in Safe Boot/Mod

  • DocumentSplitter and memory

    Regarding the DocumentSplitter class that allows for the SAX parsing of large XML documents. Is there a way to free the memory of each of the "temporary" XMLDocuments that get created? I know there's a XMLNodeCover.freeDocument(int id) method in the

  • T420s - best 8 hours battery setup

    Hello Community, I just bough T420s 4GB RAm, 128SSD to my girlfriend and she is SO happy. The laptop is one sexy beast. However, I was surprized by the size of the main battery. It is tiny , like a chocolate bar So , I expected a tiny battery life as

  • AutoComplete Text in Report Paramter

    Hi , I need an option like showing parameters as Auto Complete text -"Same like Ajax Tool-Auto complete Textbox". Is there any option,when user types the -Employee Name,like "A",then the report paramter lists all -Employees having -"A" as Starting..

  • Contact sync problem in Link.

    I am facing 2 problems while syncing contacts with Blackberry Link - When there are sync conflicts, the small window that appears listing all the conflicts is unresponsive and the scroll bars in it don't function. The information is not completely vi