
String methods In Java?
trim() Removes extra spaces only at the beginning and end. Example: String s = " Admin123 " ; System . out . println ( s . trim ()); // output:"Admin123" 2.equalsIgnoreCase() Compares two strings ignoring uppercase/lowercase. Example: "Vijay" . equalsIgnoreCase ( "vijay" ); // true 3.equals() vs == == checks memory reference(same object or not). equals() checks actual content/value. Example: String s1 = "java" ; String s2 = new String ( "java" ); s1 == s2 // output:false s1 . equals ( s2 ) // output:true 4.contains checks if a substring exists inside a string.Returns true or false. Example : String email = "test@gmail.com" ; email . contains ( "@" ); // output:true 5.Integer.parseInt() converts String to integer. Example : int num = Integer . parseInt ( "1234" ); System . out . println ( num + 10 ); // output:1244 6.split() + loop(count word) split sentences into words and count occurrences. Example : String s = "java is easy java is powerful" ; String [] arr = s . split ( " " ); int c
Continue reading on Dev.to Webdev
Opens in a new tab




