Encode a String to UTF-8 in Java
When working with Strings in Java, we oftentimes need to encode them to a specific charset, such as UTF-8. UTF-8 represents a variable-width character encoding that uses between one and four eight-bit bytes to represent all valid Unicode code points. A code point can represent single characters, but also have...
How to Filter a Map by Key or Value in Java
Map implementations in Java represent structures that map keys to values. A Map cannot contain duplicate keys and each can at most be mapped to one value. The Map<K,V> implementations are generic and accept any K (key) and V (value) to be mapped. The Map interface...
Java 8 – How to Sort List with Stream.sorted()
A stream represents a sequence of elements and supports different kind of operations that lead to the desired result. The source of these elements is usually a Collection or an Array, from which data is provided to the stream. Streams differ from collections in several ways; most notably in that...
Java: Check if String Starts with Another String
In this article, we'll take a look at how to check if a String starts with another String in Java. This is is a fairly common task in programming, and is very similar to checking if a string contains a substring. For example, this can come in useful if we...
Guide to Apache Commons' StringUtils Class in Java
The Apache Commons library provides many new interfaces, implementations and classes that expand on the core Java Framework. It's one of the top third-party libraries and is present in many projects. In this article, we've compiled a Guide to Apache Commons' StringUtils class, which provides some very good utilities and...
Java: Check if Array Contains Value or Element
Whether in Java, or any other programming language, it is a common occurrence to check if an array contains a value. This is one of the things that most beginners tend to learn, and it is a useful thing to know in general. In this article, we'll take a look...