Code
for Program to show an example of creating a String object from a StringBuffer
Object in Java
public class java
{
public static void main(String[] args)
{
stringbuffer
sb=new stringbuffer("Many hands make light work");
system.out.println("StringBuffer
: " + SB);
string str=SB.toString( );
system.out.println("String : " + Str);
}
}
Code for Program to show an example of Calling a Base Class Method from a Derived Class in Java
public class java
{
public static void main(String[] args)
{
dog adog=new dog("Fido","Chihuahua");
dog stardog=new dog("Lassie");
system.out.println(aDog);
system.out.println(starDog);
}
}
Code for Program to show an example of using a Static Nested Class outside the Top-Level Class in Java
public class java
{
public static void main(String[] args)
{
system.out.println(new magichat("Gray Topper"));
system.out.println(new magichat("Black Topper"));
system.out.println(new magichat("Baseball Topper"));
magichat oldhat=new magichat("Old hat");
magichat.rabbit rabbit=oldhat.new rabbit( );
system.out.println(oldHat);
system.out.println("\nNew rabbit is : " + rabbit);
}
}
Code for Program to show an example of modifying String objects in Java
public class java
{
public static void main(String[] args)
{
string
str="To be or not to be";
system.out.println("The Original String is : " + Str);
str=str.replace('
','%');
system.out.println("The
Replaced String is : " + Str);
str=" This is a String. ";
system.out.println("\nThe
Original String is : " + Str);
str=str.trim( );
system.out.println("The Trimed String is : " + Str);
}
}
Code for Program to show an example of creating Character Arrays from String objects in Java
public class java
{
publicstaticvoid main(String[] args)
{
string str="To be or not to be";
char[] carray_1=str.tochararray( );
char[] carray_2=newchar[6];
str.getchars(9,15,carray_2,0);
system.out.println("The String is : " + Str);
system.out.println("The character array-1 is : ");
for(int i=0;i
system.out.println(carray_1[i]);
system.out.println("The character array-2 is : ");
for(int j=0;j
system.out.println(carray_2[j]);
}
}
No comments:
Post a Comment