Exforsys
+ Reply to Thread
Results 1 to 3 of 3

Object Count..

This is a discussion on Object Count.. within the Java forums, part of the Programming Talk category; Can anybody help me to count how many objects are created during runtime in a java class as... As in... ...

  1. #1
    singhsn is offline Junior Member Array
    Join Date
    Sep 2007
    Answers
    3

    Thumbs up Object Count..

    Can anybody help me to count how many objects are created during runtime in a java class as...

    As in...

    String s1="abc";
    s1.concat(s1);
    s1.replace('a','z');

    How many String objects will be created(With explanation please...)

    Any help on this will be highly appreciated.
    Thanks


  2. #2
    vickyas400 is offline Junior Member Array
    Join Date
    Nov 2007
    Answers
    7
    Hi.
    Am not sure of your question. If you want to know the no of objects created by your class. You can have a counter variable in your constructor that can be just incremented . This will help to find out the no of objects actually created by the class.


  3. #3
    amitky is offline J2EE Prof. Array
    Join Date
    Dec 2007
    Location
    Bangalore
    Answers
    7

    Hi

    String functions always return a new string object after manipulation. So here there are 3 object created.
    String s1="abc"; One s1
    s1.concat(s1); One return of this
    s1.replace('a','z'); One return of this


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...