• 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

String and StringBuffer

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1 Public class test (
2 Public static void stringReplace (String text) (
3 Text = text.replace ('j' , 'i');
4 )
5
6 public static void bufferReplace (StringBuffer text) (
7 text = text.append ("C")
8 )
9
10 public static void main (String args[]} (
11 String textString = new String ("java");
12 StringBuffer text BufferString = new StringBuffer ("java");
13
14 stringReplace (textString);
15 bufferReplace (textBuffer);
16
17 System.out.printLn (textString + textBuffer);
18 }
19 )
What is the output?
 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


public class Test
{
public static void stringReplace (String text)
{
text = text.replace ('j' , 'i');
}

public static void bufferReplace (StringBuffer text)
{
text = text.append ("C") ;
}

public static void main (String args[])
{
String textString = new String ("java");
StringBuffer textBuffer = new StringBuffer("java");
stringReplace(textString);
bufferReplace(textBuffer);
System.out.println (textString + textBuffer);
} //main

}//Test



Output: javajavaC

for understanding try this code

class K
{
public static void main(String args[])
{
String s="java";
s.replace('j','p');
System.out.println(s); //Strings are imutable

StringBuffer sb=new StringBuffer("s");
sb.append("C");
System.out.println(sb);
}//main
}//class


Output: java
sC

Regards
Naresh
 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The answer will be
----------
javajavaC
----------
 
xie li
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank u
 
reply
    Bookmark Topic Watch Topic
  • New Topic