String Manipulation is the most important part of Java language.String is a collection of Alpha-numeric characters i.e. it may contain Alphabets,Numbers and Special characters.Strings can be reprented in Java in two different ways:
String s1="Kodingpoint";
System.out.println(s1);
String s1="Kodingpoint"
String s2=new(s1);
System.out.println(s2);
For using these input methods,we had writed a code,which will make you understand Strings better:
WAP in Java to input the String
class strings{
public static void main(String args[])
{
char ch[]={'K','o','d','i','n','g', 'P','o','i','n','t'}; //Char enter words character by character
String s1="Java Blog"; //Characters entered in String
String s2=new String(s1); //String object created using new keyword
System.out.println(s2+"\n");
System.out.println(s1+"\n"); //String object created using string literal
System.out.println(ch);
}
}
Here is the output:
- Using String literals.
- Using new keyword
Using String literal:In this method we declare a String Literal for our String. The syntax for declaring String in this method is :
String s1="Kodingpoint";
System.out.println(s1);
Using New keyword:It is the common way,as we use new keyword to allocate memory and to input.The syntax is:
String s1="Kodingpoint"
String s2=new(s1);
System.out.println(s2);
For using these input methods,we had writed a code,which will make you understand Strings better:
WAP in Java to input the String
class strings{
public static void main(String args[])
{
char ch[]={'K','o','d','i','n','g', 'P','o','i','n','t'}; //Char enter words character by character
String s1="Java Blog"; //Characters entered in String
String s2=new String(s1); //String object created using new keyword
System.out.println(s2+"\n");
System.out.println(s1+"\n"); //String object created using string literal
System.out.println(ch);
}
}
Here is the output:
0 comments: