java string %s code example

Example 1: formartted string java

String str = String.format( "Hello \n World \n my name is %s and i'm %d years old" , "Paul", 27);

Example 2: how to make a string java

String newString = "Hello World";

Example 3: string java

System.out.println("abc");
     String cde = "cde";
     System.out.println("abc" + cde);
     String c = "abc".substring(2,3);
     String d = cde.substring(1, 2);

Example 4: string method example in java

public char charAt(int index)
-----------------------------
String x = "airplane";
System.out.println( x.charAt(2) ); // output is 'r'

Example 5: string method example in java

public int length()
-----------------------
String x = "01234567";
System.out.println( x.length() ); // returns "8"

Example 6: string java

String str = "abc";

Tags:

Java Example