• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

substring confusion...

 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Options :
A: Hell Hello
B: Hel Hel
C: Hel Hello
D: Hell Hell
Answer : c)It will print Hel Hello
I cannot understand from where did this Hello come from.
and where is 'r' in Hello??
please explain
Sonir
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
its very simple
1) what does this result in
System.out.print(str.substring(0,3));

It will result in Hel since starting point is 0 and count upto 3 characters(remember the first element in indexed 1)

2)System.out.println(str.replace('r', 'h'));
after this is executed there is no match and the same string is retturned
so it is Hello refer to API for more details.
-A
 
reply
    Bookmark Topic Watch Topic
  • New Topic