Back to articles
Java String Methods You'll Actually Use Every Day

Java String Methods You'll Actually Use Every Day

via Dev.to TutorialManikanta Yarramsetti

I remember when I first started learning Java, strings felt weirdly complicated. Like, why so many methods? Which ones do I even need? Turns out, you only need a handful 90% of the time. Here they are. The Ones That Matter length() — gives you the number of characters. String name = "Ravi" ; System . out . println ( name . length ()); // 4 toUpperCase() / toLowerCase() — case conversion, simple as that. String city = "chennai" ; System . out . println ( city . toUpperCase ()); // CHENNAI trim() — removes extra spaces from both ends. Super useful when handling user input. String input = " hello " ; System . out . println ( input . trim ()); // "hello" contains() — checks if a string has a certain word or character inside it. String msg = "Java is fun" ; System . out . println ( msg . contains ( "fun" )); // true replace() — swap out characters or words. String s = "I like cats" ; System . out . println ( s . replace ( "cats" , "dogs" )); // I like dogs substring() — grab a piece of the

Continue reading on Dev.to Tutorial

Opens in a new tab

Read Full Article
1 views

Related Articles