How to check string from front and back?

How to check string using startsWith and endsWith function?

Let’s see videos and program on how to check string using endsWith and startsWith function.

In this blog, we will check string from front and back part. startsWith() and endsWith() functions work on check string.

 

Video On endsWith and startsWith Function


 

class str4

{

                public static void main(String args[])

                {

                                String str = “Welcome in Java String”;

                                // Want to check Welcome word first position on not

                                System.out.println(str.startsWith(“Welcome”)); // Return true

                                System.out.println(str.startsWith(“Java”));          // return false

 

                                // Let’s Check endsWith -> work same as startsWith

                                System.out.println(str.endsWith(“String”));        // return true

 

                                String employee[] = {“Patel Vijay”,”Vyas Ronit”,”Patel Dhara”,”Jain Bhaumik”,”Vyas Hitesh”};

                                String surname = “Jain”;                // Let’s Find Employee

                                for(int i=0;i<employee.length;i++)

                                {

                                                if(employee[i].startsWith(surname))     // Find start position of Surname

                                                                System.out.println(employee[i]); // Display Employee Name…

                                }

                }

}

 

Output:

True

False

True

Jain Bhaumik


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

1149total visits,1visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

Comments are closed.