class StringsDemo
{
   public static void main(String[] args)
   {
            System.out.println("*** DEMO: Use of string method trim() to eliminate empty spaces on an array of strings ***");

         String[] fruits = {" apple", "plum ", "    orange  "};  // array of strings that holds fruit names
            String str;

         // process the array to remove any leading/trailing whitespaces from each element
         for(String s: fruits)
         {
            // assigning trimmed string value to string str and printing out trimmed string
            str = s.trim();
            System.out.println("Fruit: " + str);

           }
            System.out.println("\n");

            System.out.println("*** DEMO: Use of string method charAt() on strings ***");
            
           // our test string
           String s1 = "abcdef";                     
           // char array to store string characters
           char[] myArray = new char[s1.length()] ;  

            // assiging value of each character found in s1 to array of char.
           for (int i = 0; i < s1.length(); i++)
           {
            // assiging value of each character found in s1 to array of char and printing out each element of array
            myArray[i] = s1.charAt(i);
            System.out.println("MyArray [" + i + "] = " + myArray[i]);
            }

            System.out.println("\n*** DEMO: Use of string method endsWith() on strings ***");

            String s2 = "go to the end";           // our test string

            // checking if test string s2 ends with suffix "end" and printing the result
            boolean result = s2.endsWith("end");
            System.out.println("string s2 ends with word 'end'? - " + result);

            System.out.println("\n*** DEMO: Counting the number of times the letter e occurs in the sentence ***");

            String text = "let's count how many letters 'e' we have in this sentence"; 
            int countLetter=0;                                                            

            //going thru the sentense and counting occurence of e letter
            for(int i=0; i< text.length(); i++)
            {
                // if char in the sentence == e increment the counter
            if (text.charAt(i)=='e')
            {
               countLetter++;
            }
         }
            // print out the result
         System.out.println("there are " + countLetter + " 'e' in this sentence");
   }
}





