Java Program To Execute Static Block

01. Example: class staticBlockExecution { public static void main(String[] args) { System.out.println("Main Method Is Executed."); } static { System.out.println("Static Block Is Executed Before Main Method."); } } Output: Static Block …

Read more

Java Program To Replace With New String

01. Example: class StringMethods { public static void main(String args[]) { int N; String string01 = “Learn Java”, newString = “”, stringContact = “”; System.out.println(string01); // Find length of string …

Read more

Java Program To Concatenation Two Strings

01. Example: class StringMethods { public static void main(String args[]) { String string01 = "Learn Java", stringContact = ""; System.out.println(string01); // Concatenating string with another string stringContact = string01.concat(" With …

Read more

Java Program To Find String Length

01. Example: class StringMethods { public static void main(String args[]) { int N; String string01 = “Learn Java”; System.out.println(string01); // Find length of string N = string01.length(); System.out.println(“Number Of Characters: …

Read more

Java Program To Create Methods

01. Example: class createMethods { // Constructor method createMethods() { System.out.println("Constructor Method: It is called when an object of it's class is created. "); } // Main method where program …

Read more

Java Program To Split String With Space

01. Example: public class splitStringSpace { public static void main(String args[]) { String string01 = "Learn Java With Zeroones"; String[] elements = string01.split("\s"); for (String element: elements) { System.out.println(element); } …

Read more

Java Program To Replace String With Another String

01. Example: public class replaceStringWithNewString { public static void main(String args[]) { String string01 = "Learn Java With Zeroones"; System.out.println("Old String:"); System.out.println(string01); System.out.println("nNew String:"); String newString = string01.replaceAll("Java", "Java And …

Read more