String concat() String length() String charAt() String compareTo() used. - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
String concat() String length() String charAt() String compareTo() used.

String concat() String length() String charAt() String compareTo() used.


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

About EasyToCode

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.