Java — Important Methods of String Class | Code Factory

String s = "Code Factory";
System.out.println(s.charAt(6)); // a
System.out.println(s.charAt(12)); // RE : java.lang.StringIndexOutOfBoundsException
String s = "Code";
s = s.concat(" Factory");
System.out.println(s); // Code Factory
String s1 = "Code";
String s2 = new String("Code");
System.out.println(s1.equals(s2)); // true
String s1 = "Code";
String s2 = new String("CODE");
System.out.println(s1.equalsIgnoreCase(s2)); // true
String s1 = "";
String s2 = new String("CODE");
System.out.println(s1.isEmpty()); // true
System.out.println(s2.isEmpty()); // false
String s1 = "Code";
System.out.println(s1.length()); // 4
String s1 = "Code";
System.out.println(s1.replace('e', 'o')); // Codo
String s1 = "Code Factory";
System.out.println(s1.substring(5)); // Factory
String s1 = "Code Factory";
System.out.println(s1.substring(5, 9)); // Fact
String s1 = "Code Factory";
System.out.println(s1.indexOf(111)); // 1
System.out.println(s1.indexOf('o')); // 1
// You can pass ASCII value of Character or Character
String s1 = "Code Factory";
System.out.println(s1.lastIndexOf(111)); // 9
System.out.println(s1.lastIndexOf('o')); // 9
// You can pass ASCII value of Character or Character
String s1 = "Code Factory";
System.out.println(s1.toLowerCase()); // code factory
String s1 = "Code Factory";
System.out.println(s1.toUpperCase()); // CODE FACTORY
String s1 = "   code factory  ";
System.out.println(s1.trim()); // code factory

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The main stories from QCon London ’19: building microservices the right way

Terra Prints: Generative Art Collections inspired by the Terra Ecosystem

Metacrafters Unite: Redefining Education for Web3 and the Metaverse Through Gaming

Passing Client Certificate to Backend with Nginx

Building Alexa skills in Python, for absolute beginners.

Overview of PYNQ project offering FPGA capabilities to Python and data engineers.

Run your first Selenium Test with Java

NomNom-3D mobile game

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

Topics for Interview: OOPS, C, C++

Factory Method Design Pattern

Annotation in Java..!

Features of Java programming language

Java training in Kochi