replace all square brackets in a string java regex

public class Main { public static void main(String[] args) { String str = “[This is a] [Test String]”; System.out.println(“String with square brackets: ” + str); str = str.replaceAll(“”,””); System.out.println(“String after square brackets: ” + str); } } Output: String with square brackets: [This is a] [Test String] String after square brackets: This is a Test … Read more

String Performance Hints

Here, we are going to discuss the performance aspect of the Java String API that includes String creation, conversion, and modification operations. Thus, analyzing the available options and comparing the efficiency to understand the way to win on performance when the application running time is critical. Constructing a New String: Strings are immutable in Java. … Read more

Inner Class Java

A class declared inside another class or interface in Java is called Java inner class or nested class. To logically group classes and interfaces in one place Java inner class is used. It thus makes it more readable and maintainable. All the members of the outer class can be accessed by an inner class including … Read more

test

[wshs_list post_type=”post” name=”Post Sitemap” order_by=”date” taxonomy=”category” terms=”c-sharp”]

Java Operators

1. Operand : Arguments on which operation is performed are known as operand.   2. Operator: Operator is a special symbol used for performing a specific task. e.g.  A+B. Here + symbol represents the operator.   3. Expression: A sequence of operands connected by operators is known as expression. e.g.  A+B*5.

Arrays in Java

Array in java represents a group of fixed homogeneous elements that can be referenced with same variable. Array elements storage is index based and follow the mechanism of contiguous memory location which states that 1st element will store at index 0, 2nd element will store at index 1, 3rd element will store at index 2 … Read more

Java Runtime freeMemory() and totalMemory() method

public class Test { public static void main(String[] args) { Runtime runtime=Runtime.getRuntime(); System.out.println(“Total Memory: “+runtime.totalMemory()); System.out.println(“Free Memory: “+runtime.freeMemory()); for(int i=0;i

Java Runtime availableProcessors

public class Test { public static void main(String[] args) { try { System.out.println(Runtime.getRuntime().availableProcessors()); } catch (Exception e) { e.printStackTrace(); } } }