You are here:   HomeJava ProgrammingJava ArrayGetting Length of an Array in Java
by Dinesh Thakur Category: array

 

class StringClasses 

{
                    public static void main (String args[])
                   {
                        String s = "God is Great";
                        String t = "Believe in God";
                        char k[]=new char[20];
                        int i,n,m;
                        if(s.startsWith("God"))
                        {
                                    System.out.println("The string begins with the word God");
                        }
                        if(s.endsWith("Great"))
                        {
                                    System.out.println("The string ends with the word Great");
                        }
                        s.getChars(4,6,k,0);
                        System.out.print("The contents of character array are :");
                        System.out.println(k);
                        if(s.regionMatches(0,t,11,3))
                        {
                                    System.out.println("The specified region in two strings do match ");
                        }
                        if(s.compareTo(t) <0)
                        {
                                    System.out.println("The string s is smaller in alphabetical order then string t ");
                        }
                        else
                        {
                                    System.out.println("The string s is greater in alphabetical order then string t ");
                        }
                        n=s.length();
                        System.out.println("The string s displayed one character per line ");
                        for(i=0;i<n;i++)
                        {
                                    System.out.println(s.charAt(i));
                        }
                        m=t.lastIndexOf('e');
                        System.out.println("The last occurense of character e in string t is at location "+m);
             }
}

String Classes in Java Examples