startsWith method in java

String str="hello";
	System.out.println(str.startsWith(""));

why it prints true as output?

Hello Pankaj, this is because that’s how the API was designed, see the javadoc.

But more seriously, one analogy can be to look at sets. Let’s imagine a string is a set of characters, then the empty string is the empty set. In set theory, the empty set is always part of any set.

Start your Java learning with us from basic to advance.Java String startsWith() method is used to check the prefix of string. It verifies if given string starts with argument string or not. startsWith() method is overloaded method and has two forms: boolean startsWith(String str) – returns true if the str is a prefix of the String.If are interested to learn about Java then contact to Cetpa or contact at :
https://www.cetpainfotech.com/technology/java-training