Search This Blog

Monday, 10 March 2014

String Methods in java


package stringfunctions;

import java.lang.String;
class Strings
{
    public static void main(String[] args)
    {
        String str="sanjay kumar singh";
        String str2="Sanjay Kumar Singh";
        String str3=" sanjay  kumar   singh  ";
        String str4="sanjay";
        String str5=" kumar singh";
       
        System.out.println(str.charAt(5));
        System.out.println(str2.compareTo(str));
        System.out.println(str.compareToIgnoreCase(str2));
        System.out.println(str.endsWith("singh"));
        System.out.println(str4.concat(str5));
        System.out.println(str.length());
        System.out.println(str3.trim());
        System.out.println(str2.equals(str));
        System.out.println(str2.equalsIgnoreCase(str));
        System.out.println(str.indexOf('k'));
        System.out.println(str.startsWith("singh"));
        System.out.println(str.indexOf("kumar"));
        System.out.println(str.substring(6));
        System.out.println(str.substring(6, 12));
        System.out.println(str4.replaceAll("sanjay","neeraj"));
    }
}

Output


No comments:

Popular Posts