"a"+"b"+"c", how many String objects created?

Hello everyone,
String s = "a" + "b" +"c";
How many String objects are created?
I guess 5, is it right?
regards

> How many String objects are created?
>
I guess 5, is it right?
Nope. Just one.

Similar Messages

  • How many string objects - please suggest

    Hi there,
    Can you somebody please tell how many String objects will be created when the following method is invoked?
    public String makinStrings() {
    String s = “Fred”;
    s = s + “47”;
    s = s.substring(2, 5);
    s = s.toUpperCase();
    return s.toString();
    Thanks
    Shan

    Hi VShan,
    This is your code
    public String makinStrings() {
    String s = “Fred”;     //1
    s = s + “47”;            //2
    s = s.substring(2, 5);//3
    s = s.toUpperCase(); //4
    return s.toString();     //5
    EXPLANATION : String is an immutable object, that means the String object cannot change it's contents.It might sound very unfamiliar but it is TRUE. In line 1: You declare a String object by assigning a a String literal "Fred" to the variable s. Now when you concat "47" with the original contents of s , a new memory space is allocated where s is assigned.+It is important to note+ that the previous reference of s i.e. "Fred" will be lost and now s refers to a new memory location where the contents are "Fred47" , so you have created another object in Line 2. Similarly you create another object in line3 & 4.As far my calculations you have created 4 objects.
    I would like you to kindly note that s is already a String so you can directly return s and hence there is no need of s.toString() in Line 5.You should also note that each object is also an eligible candidate for Grabage Collection.
    So as soon as Line2 gets executed , the object in Line1 becomes eligible for garbage collection.. that means when GC runs that object will be reclaimed and hence memory will be freed.

  • How many String objects will be created when this method is invoked?

    public String makinStrings() {
    String s = �Fred�;
    s = s + �47�;
    s = s.substring(2, 5);
    s = s.toUpperCase();
    return s.toString();
    }

    Teachers.Obviously. Why? Is it really important?
    Not in my experience. StringBuffer can be important, occasionally. Very occasionally: about 4 times in the last 10 years for me. How many Strings? not important.

  • How many String are created?

    public String makinStrings() {
         String s = �Fred�;
         s = s + �47�;
         s = s.substring(2, 5);
         s = s.toUpperCase();
         return s.toString();
    }How many objects are created when this method is called?
    My answer is 5
    1. "Fred"
    2. "47"
    3. "Fred47"
    4. "ed4"
    5. "ED4"
    But my friend is telling it is 3.
    1. "Fred"
    2. "47"
    3. "Fred47"
    I know that any method called on String object creates a brand new String. Please help me with the solution whether it is 3 or 5.

    hi,
    First of all i want to thanks for all of your replies.
    My friend is saying that when we say "How many objects when method is invoked" it means at runtime. String literals are not created at run time.
    String s = �Fred�; // No object is creatd here
    s = s + �47�; // One object created "s"
    s = s.substring(2, 5); //Another object "s"
    s = s.toUpperCase(); //Another object "s"
    return s.toString();
    Hence total 3 objects.
    Now the i have got a doubt. Are String literals created at Complie time itself. Or since String s = "Fred" is a compile time constant field. And String literal "47" is also a compile time constant field.
    Suppose if the code is like this
    String s = new String("Fred")
    String s1 = s; ---------------- Then is this String object created at Run time.
    String s2 = "47" ----------- This object is created at Complie time.
    Please clarify my doubt.

  • How many view object instances can create from Single Entity ?

    Hi All,
    JDev Ver : 11.1.1.5
    I want to How Many view objects can i create from the single entitiy ?
    Is there any limit ?
    Thanks,
    Gopinath

    No, there is no limit

  • How many tables are created in Master data loading ( Including hierchy )

    hi ,
    Please anybody , can you tell us how many tables are created in Master data loading ( Including hierchy )
    thanks
    Phani

    Hi PP,
    Depending upon the definition of an infoobject, the tables are created when the objects are activated.
    /BI<C OR DIGIT>/<TABLE CODE><INFOOBJECT>
    <C or digit>: C = Customer-defined InfoObjects
    digit = SAP-defined InfoObjects
    <table code>: S = SID table
    T = Text table
    P = Time-independent master data attributes
    Q = Time-dependent master data attributes
    M = Union of time-dependent and time-independent master
    data attributes
    X = SID table for time-independent navigational attributes
    Y = SID table for time-dependent navigational attributes
    H = Hierarchy table
    K = Hierarchy SID table
    I = Hierarchy SID structure table
    J = Hierarchy interval table
    Thnaks...
    Shambhu

  • How to find how many sto's Created in One plant

    Dear
    how to find how many sto's Created in One plant
    ex: i have 5 plants now i want to check how many sto's done

    Hi,
    Please check in table EKKO for supplying plant against STO document
    EKPO against Receving plant
    WB2_V_EKKO_EKPO2 - You can pass both supplying plant as well as receving plant.
    Regards,
    Haresh

  • How many dimensions can create in BPC

    Hi friends
    How many Dimension can create in Dimension Library in BPC NW
    Lion

    Hi Surender,
    You have any no. of Dimensions in Dimension library.
    In a BPC Application the mandatory Dimensions are Account, Category, Entity and TIme.
    In an Appset you should have Intercompany Dimesion.
    The other are D - Datasource dimension and User defined Dimensions.
    Regards,
    Raghu

  • How many sessions are created in Server ?

    Hi All developers,
    SCJP back again.........
    Anybody please tell me......
    Is there any way to find out how many sessions are created in server ?
    Thanks in advance ..............

    Only by keeping track of them yourself.
    The various session listeners - SessionListener, SessionBindingListener are usefule here.

  • When we create a queue how many files get created???

    Hi All,
              When we create a resource suppose a queue then how many files get created or modified from that action internally??
              Thanks in advance
              Sumeet

    In 8.1, one file: "config.xml"; in 9.0 one or two files (your JMS module file, and potentially the config.xml) .

  • How many hash partitions create is prefer

    I want to create hash partitions on a large table,but i don't know how many partitions to create?
    create table T_PARTITION_HASH
      ID   NUMBER,
      NAME VARCHAR2(50)
    partition by hash (ID)
      partition T_HASH_P1
        tablespace USERS,
      partition T_HASH_P2
        tablespace USERS,
      partition T_HASH_P3
        tablespace USERS
    );

    Agustin UN wrote:
    What is the table size in rows and Mb?
    What is the grow estimated of table?
    What access is on table?
    . :-) Any help with my english will be welcome :-).the table contain about 1 hundred million rows.
    the table grows 1000000 rows per day.
    the table is use for statistical analysis in data wasehouse.
    Edited by: user7244870 on Nov 5, 2010 2:22 AM

  • How many ways to create servlets

    Hi
    i have some confusion. how many ways to create servlets.
    as of my knowledge 3 ways 1) implementing Servlet 2) extending GenericServlet 3) extending HttpServlets.
    can any one tell me this is correct or not.

    The only correct way (IMHO) to declare a Servlet is to implement Servlet... Extending GenericServlet or HttpServlet has (almost) the same effect it's not self documentingIf it's an HTTP servlet the only correct way is to extend HttpServlet, unless you really want to reinvent the wheel. You can add 'implements Servlet' if you insist but it is entirely redundant. The Javadoc will be the same in either case.
    In other words I don't know what this poster is talking about.

  • How much RAM do tab groups use (on average)? Do I need to watch out for how many groups I create?

    I may have gone overboard in the creation of Tab Groups. I say this because now my system is beginning to act a bit sluggish. I created 7 groups, two of which have 9 or 10 tabs. Should I pull back on the number of groups I create (as well as how many tab are located within each group). That is: How much RAM do tab groups use. How can I calibrate or understand the trade off between these markers and the amount of RAM they use?

    You can see the memory usage on the about:memory page.
    You can open about: pages via the location bar like you open a website.

  • How to identify objects created by registering xml schema

    Hi Everyone,
    We are using Oracle 9i Rel2. I have registered an XML schema and I saw that there were several objects created for it table ,some types and a trigger . For some build purposes I want to exclude all of these objects which are associated with xml schema and should be able to drop and recreate the whole of oracle schema.
    I see the user_types table does not have any parameter to indicate that these are autogenerated or are different. In user_types they look like any other type that a user would have created. Do any of you know how to differentiate these types created by registering XML schemas from the normal types.
    Thanks for your help

    There is no way I know of to differentiate between a type created by Schema Registration and another Type. You can query the XML Schema itslef to get the Typenames it relies on.
    SQL> --
    SQL> SQL> select nvl(extractvalue
    2 (
    3 value(ct),
    4 '/xs:complexType/@name',
    5 'xmlns:xs="http://www.w3.org/2001/XMLSchema"
    6 xmlns:xdb="http://xmlns.oracle.com/xdb"'
    7 ),'Local Complex Type') COMPLEX_TYPE,
    8 extractvalue
    9 (
    10 value(ct),
    11 '/xs:complexType/@xdb:SQLType',
    12 'xmlns:xs="http://www.w3.org/2001/XMLSchema"
    13 xmlns:xdb="http://xmlns.oracle.com/xdb"'
    14 ) SQL_TYPE
    15 from user_xml_schemas,
    16 table
    17 (
    18 xmlsequence
    19 (
    20 extract
    21 (
    22 schema,
    23 '//xs:complexType',
    24 'xmlns:xs="http://www.w3.org/2001/XMLSchema"
    25 xmlns:xdb="http://xmlns.oracle.com/xdb"'
    26 )
    27 )
    28 ) ct
    29 /
    COMPLEX_TYPE
    SQL_TYPE
    PurchaseOrderType
    PURCHASEORDER_T
    LineItemsType
    LINEITEMS_T
    LineItemType
    LINEITEM_T
    COMPLEX_TYPE
    SQL_TYPE
    PartType
    PART_T
    ActionsType
    ACTIONS_T
    Local Complex Type
    ACTION_T
    COMPLEX_TYPE
    SQL_TYPE
    RejectionType
    REJECTION_T
    ShippingInstructionsType
    SHIPPING_INSTRUCTIONS_T
    Local Complex Type
    ROOT_T
    COMPLEX_TYPE
    SQL_TYPE
    Local Complex Type
    P222_T
    10 rows selected.
    SQL>

  • How many copa tables created after creation operating concern?

    Hi gurus
    How many copa tables will be created after just creation of  OPERATING CONCERN?
    This is question being asked in interview.
    Regards
    Hari P
    Edited by: Hari Peddi on Feb 15, 2009 11:22 AM

    Hi,
    As the previous comment says, CE1XXXX, CE2XXXX, CE3XXXX and CE4XXXX are created. But this is if you are using Costing-based profitability analysis, However, if you're using account-base PA then no tables are created and CPEP, COSP, COSS and other standard CO tables are used.
    Regards,
    Kenneth

Maybe you are looking for