java怎么判斷字符串是否包含指定字符?針對這個(gè)問題,這篇文章詳細(xì)介紹了相對應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問題的小伙伴找到更簡單易行的方法。
1、startsWith()
public boolean startsWith(String prefix, int toffset) or public boolean startsWith(String prefix)
import java.io.*; public class Test{ public static void main(String args[]){ String Str = new String("Welcome to Yiibai.com"); System.out.print("Return Value :" ); System.out.println(Str.startsWith("Welcome") ); System.out.print("Return Value :" ); System.out.println(Str.startsWith("Tutorials") ); System.out.print("Return Value :" ); System.out.println(Str.startsWith("Yiibai", 11) ); } }
public static void main(String[] args) { String str = "abc"; boolean status = str.contains("a"); if(status){ System.out.println("包含"); }else{ System.out.println("不包含"); } }
public static void main(String[] args) { String str1 = "abcdefg"; int result1 = str1.indexOf("ab"); if(result1 != -1){ System.out.println("字符串str中包含子串“ab”"+result1); }else{ System.out.println("字符串str中不包含子串“ab”"+result1); } }
關(guān)于java怎么判斷字符串是否包含指定字符問題的解答就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,如果你還有很多疑惑沒有解開,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
分享標(biāo)題:java中判斷字符串是否包含指定字符的方法-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://www.rwnh.cn/article12/ddopdc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)建站、用戶體驗(yàn)、網(wǎng)站營銷、App設(shè)計(jì)、虛擬主機(jī)、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容