String क्लास का उपयोग कैरेक्टर स्ट्रिंग्स को दर्शाने के लिए किया जा सकता है, Java प्रोग्राम में सभी स्ट्रिंग लिटरल्स को String क्लास के इंस्टेंस के रूप में लागू किया जाता है। Strings कॉन्स्टेंट हैं और उनके मान बदले नहीं जा सकते (अपरिवर्तनीय) एक बार बनने के बाद।
हम String क्लास के startsWith() मेथड का उपयोग करके जांच सकते हैं कि कोई स्ट्रिंग किसी विशिष्ट स्ट्रिंग से शुरू होती है या नहीं, यह एक बूलियन, true या false लौटाता है।
सिंटैक्स
public boolean startsWith(String prefix)
उदाहरण
public class StringStartsWithSubStringTest { public static void main(String[] args) { String str = "WelcomeToTutorialsPoint"; if(str.startsWith("Welcome")) { System.out.println("Begins with the specified word!"); } else { System.out.println("Does not begin with the specified word!"); } } }आउटपुट
Begins with the specified word!