HomeContact

Using the StartsWith Method in Java in the String

Published in Java
May 18, 2023
1 min read

String has a startsWith() method. This is a method used to compare the starting strings of the String value. That is, it functions to check whether the string starts with a designated single character(s).


🌱Sample

public class Test {
public static void main(String[] args) {
String str = "code-journey.com";
System.out.println(str.startsWith("code")); // true
System.out.println(str.startsWith("Code")); // false
System.out.println(str.startsWith("com")); // false
System.out.println(str.startsWith("o")); // false
System.out.println(str.startsWith("c")); // true
}
}

Of course it’s a baby, but it’s case sensitive.


Tags

#Java#java.lang

Share


Previous Article
Using the substring method in Java

Topics

Java
Other
Server

Related Posts

How to use BigInteger in Java - 2
May 31, 2023
1 min