KnowledgeBoat Logo
|

Computer Applications

What will be the output of following code?

String c = "Hello i love java"; 
boolean var;
var = c.startsWith("hello"); 
System.out.println(var);
  1. true
  2. false
  3. 0
  4. 1

Java String Handling

2 Likes

Answer

false

Reason — An important point to note in this code is that startsWith() method in Java is case-sensitive, meaning it will differentiate between uppercase and lowercase characters. In this case, the prefix "hello" starts with a lowercase 'h', but the string in c starts with an uppercase 'H'. Since the cases don't match, the startsWith() method will return false. So var will be assigned false and given as output.

Answered By

1 Like


Related Questions