The java string concat() method combines specified string at the end of this string
class ConcatDemo
{
public static void main(String[]args)
{
String s1="shashi";
String s2=new String("kushwaha");
System.out.println(s1.concat(s2));
}
}
Output
shashikushwaha
* It returns count of total number of characters. The length of java string is same as the unicode code units of the string.
class LengthDemo
{
public static void main(String[]args)
{
String s1="shashi";
System.out.println(s1.length());
}
}
Output
6
The java string charAt() method returns a char value at the given index number.
class CharAtDemo
{
public static void main(String[]args)
{
String s1="prince";
System.out.println(s1.charAt(4));
}
}
Output
c
* It returns positive number, negative number or 0.
class CompareToDemo
{
public static void main (String args[])
{
String s1="hello";
String s=new String("hellos");
System.out.println(s1.compareTo(s));
}
}
Output
-1
0 comments:
Post a Comment