如何在java中检查字符串是否以子字符串开头? [英] How to check a string starts with a substring or not in java?

查看:125
本文介绍了如何在java中检查字符串是否以子字符串开头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查一个以 http:// 开头的字符串。如果没有循环我怎么能这样做?在此先感谢。

I want to check a string which starts with http:// or not. How can I do that without loop? Thanks in advance.

推荐答案

使用 public boolean startsWith(String prefix) String API

例如: boolean isStartsWith = YOUR_STRING.startsWith(http://);

String tst = "http://web.com";
System.out.print(tst.startsWith("http://")); //prints true

这篇关于如何在java中检查字符串是否以子字符串开头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆