• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How many String Objects are created?

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q1)How many String Objects are created? and what are they?
Also can you tell me how test how many String Objects are really created?
I am thinking 5 String Objects-
1)test
2)56
3)s.substring(2, 5)=st5
4)s.toUpperCase()=ST5
5)s.toLowerCase()=st5



Q2)why the followinggives error saying that it cannot construct Short
Short y= new Short("6");
Short y= new Short(6);
Short y= new Short((short)6);
 
Ranch Hand
Posts: 175
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Q1 : I think it will create 5 string objects because asper the code
s = s.toLowerCase() object is already present in the pool so it will simply reuse it rather then re creating it.

Q2 : will give compile time error becuase of Short y= new Short(6); in this case 6 is integet(int) liternal Short doesnthave this constructor so Short y= new Short((short)6); will compile.

Thanks
 
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you wanted to day it creates 4 objects if the "Lower case" is reused.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic