Java developer? Don't confuse them! Very similar, but completely different things! List.of() vs Arrays.asList() When to use them: List.of() → when you need an immutable list (best option for constants, configurations, test data). Arrays.asList() → when you need to quickly get a list from an array and be able to change elements using set(). In practice, List.of() is more commonly used in modern code because it is safer and clearly shows immutability. record vs class A record is a special type of class in Java 16 designed to store immutable data (data carrier). The compiler automatically generates the constructor, getters, equals(), hashCode(), and toString(). Good for DTOs, responses, value objects, and immutable data. A class is a regular full-fledged type. It is suitable for objects with behaviour, mutable state, and complex logic. Suitable for entities, service models, objects with logic or mutable state. String.isEmpty() vs String.isBlank() isEmpty() only checks the length of the string. It returns true if the length of the string is 0. isBlank() (introduced in Java 11) checks whether the string consists only of whitespace characters: spaces, tabs, line breaks, etc. In other words, it actually performs a trim()-like check. In most cases, when validating user input, it is better to use isBlank(), because the string " " is usually also considered empty. #Java #Programming #Software #JavaEE #Backend
.is empty(); .isBlank(). Anyway next one will be .allowedCharsOnly()
Useful stuff!
Love the way access specifiers repeat till… well…🤢
I always hated the UnsupportedOperationException. I may argue, if the method is not supported, why is it there in the first place? Feels bad. List Interface may be the answer here and legacy.