• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

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.
 
Did Steve tell you that? Fuh - Steve. Just look at this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic