[英]How to check a string starts with a substring or not in java?
我想檢查是否以http://
開頭的字符串。 我怎么能在沒有循環的情況下做到這一點? 提前致謝。
在String API 中使用public boolean startsWith(String prefix)
例如: boolean isStartsWith = YOUR_STRING.startsWith("http://");
String tst = "http://web.com";
System.out.print(tst.startsWith("http://")); //prints true
您基本上可以使用最簡單的方法......即String API提供的方法..
public boolean startsWith(String prefix, int toffset)
or
public boolean startsWith(String prefix)
例如 :
String str = new String("http://www.google.com");
str.startsWith("http://");
滿足條件返回真,否則返回假。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.