java startswith
时间: 2023-05-26 09:01:46 浏览: 120
Java探索之string字符串的应用代码示例
The `startsWith()` method in Java is used to determine whether a string starts with a specified prefix. This method is a part of the String class and returns a boolean value. Its syntax is:
```
public boolean startsWith(String prefix)
```
Here, the `prefix` parameter specifies the prefix to check in the string.
Example:
```java
String str = "Hello World";
boolean result = str.startsWith("Hello");
if(result) {
System.out.println("The string starts with 'Hello'");
} else {
System.out.println("The string does not start with 'Hello'");
}
```
Output:
```
The string starts with 'Hello'
```
阅读全文