String 类可以用来表示字符串,Java程序中的所有字符串文字都是作为一个实例实现的一个字符串类。字符串是常量,它们的值一旦创建就无法更改(不可变)。
我们可以使用 startsWith( String 类的 ) 方法检查字符串是否以特定字符串开头,它返回一个布尔值, true 或 false。
语法public boolean startsWith(String prefix)
public class StringStartsWithSubStringTest { public static void main(String[] args) { String str = "WelcomeToTutorialsPoint"; if(str.startsWith("<strong>Welcome</strong>")) { System.out.println("Begins with the specified word!"); } else { System.out.println("Does not begin with the specified word!"); } } }
Begins with the specified word!
以上就是如何在Java中检查字符串是否以特定子字符串开头?的详细内容,更多请关注php中文网其它相关文章!
java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号