Loop the Characters of a String
Looping the characters of a string can be done via charAt() or toCharArray() as follows: String str = “hello world”;for (int i = 0; i
Looping the characters of a string can be done via charAt() or toCharArray() as follows: String str = “hello world”;for (int i = 0; i
Starting with JDK 13, we can define multi-line strings using “”” as follows: String text = “””some textsome textsome text”””;
Let’s assume that we have a proxy at address proxy.host:8888. We can set up this proxy via the JDK 11 HttpClient as follows: HttpClient client = HttpClient.newBuilder() .proxy(ProxySelector.of(new InetSocketAddress(“proxy.host”, 8888)))
A short is a 16-bit signed integer. It has a minimum value of -215 (-32,768), and a maximum value of 215 ‘1 (32,767) short example = -32; short myShort =
Learn how to use enum effectively in a switch case block. There are multiple advantages to not making any mistakes since the originals are defined in the enum. public class
The StringJoiner class helps in formatting strings when there are multiple values and you want to present them with some delimiter and some pre and post suffixes. The delimiter, pre
The quickest way to create a custom RuntimeException is as follows (simply extend RuntimeException): public class IncorrectFileException extends RuntimeException { public IncorrectFileException(String errorMessage, Throwable err) { super(errorMessage, err); }}
The move method accepts three arguments. The 1st and 2nd being the source and target Path attributes and the 3rd being the replace option. import java.nio.file.*;import static java.nio.file.StandardCopyOption.*;public class FileMove{
In addition to the string and character escape sequences, Java has a more general Unicode escaping mechanism, as defined in JLS 3.3. Unicode Escapes. A Unicode escape has the following