Category: Lang Package

  • How do I check if a character is a whitespace in Java?

    Whitespace characters in Java (or programming in general) aren’t just the space ' ' character. It also includes other characters that create some form of space or break in the text. The most common ones include: space ' ' tab '\t' newline '\n' carriage return '\r' form feed '\f'. All these characters fall into the…

  • What is the purpose of String.strip() method of Java 11?

    The purpose of the String.strip() method in Java 11 is to remove whitespaces from both the beginning and end of a string. This is very similar to the String.trim() method available in earlier versions of Java, but there is a key difference between them. Here’s the difference: String.strip(): Introduced in Java 11, strip() uses the…

  • How do I use String.join() method in Java?

    The String.join() method in Java is a static method added in Java 8 to the java.lang.String class. The String.join() is a static utility method used to concatenate multiple strings, arrays or collections (like lists and sets) of strings. This method makes it easier to join multiple strings with a specific delimiter. A delimiter is a…

  • How do I get the number of processors available to the JVM?

    The Runtime.getRuntime().availableProcessors() method returns the maximum number of processors available to the Java virtual machine, the value will never be smaller than one. Knowing the number of available processor you can use it for example to limit the number of thread in your application when you are writing a multi-thread code. package org.kodejava.lang; public class…

  • How do I find Java version?

    The simplest way to get the Java version is by running the java -version command in your terminal application or Windows command prompt. If Java is installed and available on your path you can get information like below. java -version java version "17" 2021-09-14 LTS Java(TM) SE Runtime Environment (build 17+35-LTS-2724) Java HotSpot(TM) 64-Bit Server…