Difference between list.clear() and new instance

In the below code,
List<String> test = new ArrayList<String)();
list.add("one");
list.add("two");
list.add("three");
list.clear();
(or)
list = new ArrayList<String)();
list.add("four");
list.add("five");
What is the difference between List.clear() and creating new instance for list?

1. Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
2. Invoking clear() sets all the elements of the ArrayList to null and resets the size to 0.    public void clear() {
     modCount++;
     // Let gc do its work
     for (int i = 0; i < size; i++)
         elementData[i] = null;
     size = 0;
    }(modCount is used to detect concurrent modification and throw an Exception when needed)
Constructing a new ArrayList creates a new, different, empty ArrayList.
In many situations they might be equivalent, but not in a case where you have two or more variable references to the same ArrayList. Example (watch out for typos)ArrayList<String> stringsA = new ArrayList<String>();
ArrayList<String> stringsB = stringsA;
: // add elements to stringsA
: // stringsB refers to the same populated list
stringsA.clear(); // stringsB refers to the clear()ed list
: // add elements to stringsA again
stringsA = new ArrayList<String>(); // stringsB still refers to the populated listdb

Similar Messages

  • What is the  difference between list display and grid display in alv report

    Hai genious
    i am a new of the abap, i dont know the alv report, i have a small doubt, can u please tell me  what is the main difference between list display and grid display in alv report
    thanks&regards
    chinnu

    Hi ,
    1. For all practical purposes, they are the same.
    2. Some differences:
    a) from abap coding point of view,
    alv list is done with Function modules,
    alv gris can also be done with FM,
    but can also be done using OO concepts.
    b) Alv grid (using oo concept) requires
    designing the screen layout .
    Hence, in one screen, we can show more
    then one alv grid
    (we cannot show more than
    one alv list on one screen)
    c) ALV grid uses ActiveX controls
    present on the Presentation Server.
    Hence, it consumes More Memory
    on the presentation server.
    d) ALV LIST is Display Only.
    Whereas
    ALV Grid Can Be made EDITABLE for entry purpose.
    e) In alv grid, these options are possible,
    but not in alv list.
    without horizontal lines
    without vertical lines
    without cell merging during sorts
    display total lines above the entries
    I hope it helps.
    Regards,
    Mamta
    Edited by: Mamta Verma on Nov 27, 2008 6:41 AM

  • Difference between Special GL and New GL

    Dear SAP Gurus,
                            What is the difference between Special GL and New GL?
    Thanks & Regards,
    Sim

    Dear Sim
    If I understood logically, then your question actually refer to special purpose ledger, right ?
    If so both are almost same. Both are for you to depict parallel accounting in your SAP system by storing posting data for the various accounting principles in separate ledgers.
    Whereas special purpose ledger is more custome developed (data is stored in 'Z' table), whereas New GL is more standardised from SAP as well as advanced when compared to special purpose ledger.
    Hope I understood correctly your question and gave some useful input.
    Regards
    Siva

  • What is difference between additive delta and new status for change record

    Hi Experts
    Can any one explain me about the difference between additive delta and new status for change record with example
    if any one has a document please post it iam thank full to u
    thanks
    Ahmed
    Please search the forum before posting a thread
    Edited by: Pravender on Feb 12, 2012 1:54 PM

    Hi
    Additive delta --- We will get the changed quantity.
    say suppose you have sales order and quantity like  1111   30 which is loaded to cube(BW).
    now same record qty has changed from 30 to 40. As we have additive delta, we will get new record as 1111  10.
    new status for change record: This is same as like After image delta type in standard SAP data sources. for every change in record you should have new record.
    say if you have any number which will be generated by system for new/changed record, then you can use this.
    You can use this option when delta option set to "numeric pointer"
    Regards,
    Venkatesh

  • If unboxed how could you tell the difference between refurbished imac and new imac?

    If unboxed how could you tell the difference between refurbished imac and new imac?

    Besides all of that, you can purchase Apple Care which will extend your warranty to 3 years just like you can on a brand new iMac.
    If you're considering a "refurbished" iMac, buy it ONLY from Apple.  I believe it's your best bet.

  • Difference between application server and central instance

    Hi everyone,
    whats the difference between application server and central instance and message server. where it will be installed. and how?
    Regards
    Basis Fresher

    Hi,
    just want to clarify that is is not correct that only one enqueue process can be configured on the CI.
    Please see the documentation within transaction RZ11 for the parameter Parameter : rdisp/wp_no_enq
    Short description : number of enqueue work processes
    Parameter description :
    You can use this parameter to define the number of enqueue work processes for the instance.
    Ensure that a value >0 is only set on the central instance that provides the enqueue server (instance rdisp/enqname ). One enqueue work process on the central instance is normally sufficient (rdisp/wp_no_enq = 1); only in very large systems can a higher value be useful.
    Kind Regards
    Thomas Alt

  • Difference between IPad 3G and new IPad 4

    Hi,
    Can any one help me, what is the difference between the IPad 3 G and New IPad 4..?

    What is an Ipad 3 G?
    The main differences between iPad 4 and iPad 3 are:
    1. A6X (vs A5X) processor
         a. 2X the compute power (like Geekbench score)
         b. 2X the graphics power (more frames per second, fill rate, etc)
    2. Enhanced 4G and LTE radio
    3. Faster WIFI, plus 5 GHz N coverage
    4. Lightening connector
    5. 720p Front facing camera
    What is the same:
    1. size, weight
    2. screen resolution
    3. same storage capacities

  • What is the difference between the newInstance() and new

    would be please tell me the difference between the newInstance() and new

    Yes, kablair, you couldn't be more correct in your
    statements. I didn't pay attention to the other
    replies. But anyway, the person who has to clarify
    the question is the OP, that doesn't seem to be
    interested in this subject anymore...Strangely enougth this seems to be quite common (the OP doesn't care about the replies). This is a frustration you'll have to live with if you plan to continue replying to posts at this forum. I deal with it by don't caring about the OP's in return. What the heck, make it an interesting discussion with or without any OP.

  • What are the differences between the old and new GarageBand?

    I'm debating about purchasing the update from GarageBand '11 to the modern GarageBand.  Could someone please list out the differences between the two so I can make my decision?  I'd prefer both pros and cons, not just added features.

    First of all, going from GarageBand '11 to GarageBand 10 is a major upgrade and not just an update.  Both applications are very different.
    The good news is, that you can and should keep both versions installed. GarageBand '11 will continue to work with GarageBand 10 installed.  GarageBand 10 can use the loops and instruments from GarageBand '11, if you do not uninstall GB '11, and so your older projects can continue to work.
    There are many differences between both versions.
    GarageBand 10's user interface is more like Logic Pro X. Instead of selecting an instrument for a track and then adding effects, you select patches with predefined effects.
    GarageBand 10 introduces smart instruments:  Drummers that play automatically instead of just drum loops, smart strings, arpeggiators.
    Also new: Amp designer to create your own amps.
    It is easier to change the articulation for software instruments in the Midi Draw area,
    But quite a few features, that made GarageBand '11 great have been discontinued.  So really, keep GB '11 installed, if you upgrade. Then you can have the best of both.
    Magic GarageBand is gone.
    Podcasts are no longer supported. and the Movie track is more restrictive.
    The Sound Effect Instruments, that let you add samples to the Musical Typing keyboard are no longer supported.
    The iLife Sound effects collection if loops is missing.
    The funny predefined vocal effects for the vocal transformer are gone.
    Many instruments and loops are gone.
    Duplicating tracks links the copies, so you can no longer edit the copies individually.
    I am not sure, if my list is complete. These are just the differences, that are important for my workflow.

  • Difference between Old GL and New GL

    Hi All,
    I am very new to this community and just started my career towards SAP. I want to understand what are the major difference between the old GL and the current GLversion.
    Thank you for all your help and advice.
    Regards,
    New Joinee
    Search SDN and read help.sap.com

    please refer below link:
    ECC 6.0 New GL Functionality
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/erpfi/financials&
    SAP release notes(Older 4.6 v/s to ECCC- New releases)
    easy way of finding release notes
    http://solutionbrowser.erp.sap.fmpmedia.com
    hoe this helps
    Please assign points as way to say thanks

  • Difference between older Extreme and new one

    I have an Airport Extreme that is about 2 to 3 years old.  The difference between speed when I am plugged by ethernet into the network and when I am using the router is significant.  It drops by about 50% or more.
    Can I expect better performance from a new model?  I have mine set at 5GHZ and auto for Channel selection.
    Thanks,
    Deanna

    The new AirPort Extreme 802.11ac......which is really not so new.....can produce wireless signals theoretically approaching the same speed as an Ethernet connection......but.....and this is a big BUT......this speed will only be realized with the 802.11ac AirPort Extreme....IF....
    You also have a new Mac that is capable of receiving an 802.11ac signal....
    and....
    The Mac is located where it has line of sight with the 802.11ac AirPort Extreme.
    To be realistic, if you have a good connection with the new 802.11ac AirPort Extreme and the new Mac is located such that it has line of sight with the AirPort Extreme, you might expect to see a 25% drop in speed compared to the 50%+ that you see now.
    The current AirPort Extreme will be two years old in a few months, and Apple rarely keeps a current model for two years, so there may be a hint in there.

  • Difference between a definition and "new"

    Hi
    some objects I could istantiate with 2 methods; for example:
    String s; or
    String s = new String;
    The difference is the second way the istance is the same in all the application?

    Many thanks; the last example:
    SAXParserFactory fac =
    SAXParserFactory.newIstance();
    and
    SAXParserFactory fac = new SAXParserFactory();
    n first definition I have an unique istance of
    factory in my JVM and in the second case I could have
    more?Ignoring for the moment the protected method and abstract class issues, pretending you could do both of the above, the differences in the approaches in a general sense are:
    * The first one would give you a reference to an instance of a SAXParserFactory or a subclass while the second would give you a reference to a SAXParserFactory (not a subclass).
    * The first one might return a reference to the same object on multiple calls, while the second would create a new object every time.

  • What are the differences between the old and new data flow technology?

    I have seen many places mentioned the new data flow tech ( In BI7) are much different from the old one,, can anyone list a few differences?
    Thanks

    Hi Dylan,
        An infosource can be used in the 7 flow model, but its purpose is completely different from the 3.x model.
    In the 3.x model, the infosource consisted of 2 structures  transfer and communication.
    The transfer structure was where you specified which field in the datasource corresponds to which infoobject ie the field type.
    You now do this in the datasource maintainence in 7.0 (the tabs called proposals and fields)
    The communication structure was the structure which was available for uploading.
    You can refer the link for the 3.x flow
    [http://help.sap.com/saphelp_nw70/helpdata/en/90/64553c845ba02de10000000a114084/content.htm]
    In the 7.0 flow, you generally use a  DSO when you perform sequential transformations ie you want to change the data format or do some processing twice before you actually load to the final infoprovider.
    The sequence in this case would be
    Datasource -> transformation1 -> DSO -> Transformation 2-> DSO -> Transformation 3-> Cube
    The disadvantage of doing this, is that the DSO will store data.  To avoid this, you can use an infosource instead of a DSO.
    You can refer the below link for using 7.0 infosources
    [http://help.sap.com/saphelp_nw70/helpdata/en/7e/001342743eda2ce10000000a1550b0/frameset.htm]
    Hope this helps.
    Regards.

  • Differents between upgrade installation and new installation

    Our processes have some misbi
    Our processes sometimes misbehave. We don't know the cause. We have a DR site so we moved everything there and then everything worked with no issue. The applications are using SQL 2012
    SP2.
    All the servers are the same in the DR site as the primary site, One of the things we know to be different is that the SQL server installation in the primary site is an upgrade from 2008,
    and the one in the DR site is a new installation of SQL 2012.
    Do you think there could be a different behaver that is related to type of installation?
    Does it make scenes to reinstall the SQL in the primary site as new installation rather than upgrade?

    Hello,
    Adding to Shanky response, do the DR SQL Server instances were configured the same (about parallelism, memory, tempdb,
    etc.)?
    Hope this helps.
    Regards,
    Alberto Morillo
    SQLCoffee.com

  • Difference between refurb 2012 and new Apple TV?

    Is the refurb 2012 Apple TV with A5 any different than the model current sold as new? Are they both 3rd gen and are any specs different?

    Hi Douglas.
    A 2012 Apple TV could be a Apple TV 2 or an Apple TV3 (which was released on March 7, 2012) So it's something you need to ask when buying it.
    If it is the Apple TV 3, it will be the first one and not the revision A model which is sold today. The difference I believe is mainly in the CPU, the first model used a dual core CPU with one core closed off, the rev A version a redesigned CPU with single core but based on the dual core.

Maybe you are looking for