Learn how to efficiently extract the first n characters of a string in Java using core JDK methods and popular libraries like Apache Commons Lang and Guava.
Also find me here:
Baeldung Author
Abderrahim Azhrioun
Full Stack Developer, Java Geek, Spring Lover, and a Blogger. I believe coding should be fun and accessible to everyone ;)
Here's what I've written (so far):
Baeldung on Java
- All
- Java Dates (9)
- Java String (8)
- JPA (7)
- Java IO (6)
- Spring Boot (4)
- Persistence (4)
- Spring Data (3)
- Java List (3)
- Jackson (3)
- Spring Web (2)
- Spring MVC (2)
- Java Streams (2)
- Java Collections (2)
- Java (2)
- Core Java (2)
- Spring Persistence (1)
- REST (1)
- Java Map (1)
- Java Array (1)
- JSON (1)
- HTTP Client-Side (1)
Convert Date to Unix Timestamp in Java
Filed under Java Dates
Need Unix timestamps from dates in Java? Read further about the conversion in this short article.
Convert Long to Date in Java
Filed under Java Dates
Learn to convert a long value to a date in Java using the Java 8 Date-Time API, the legacy Date API, and the Joda-Time library.
Fixing Hibernate QueryException: Named Parameter Not Bound
Filed under Persistence
Learn to resolve the Hibernate QueryException: “named parameter not bound.” by employing the setParameter() method to assign values to named parameters.
How to Get Last Record in Spring Data JPA
Filed under Spring Data
Explore different ways of getting the last record in Spring Data JPA.
Handling NullPointerException in findFirst() When the First Element Is Null
Filed under Java Streams
To avoid NullPointerException when using findFirst() in Java, filter the stream before calling findFirst() or use Optional#ofNullable() to wrap values in an Optional object.
How to Avoid NoSuchElementException in Stream API
Filed under Java Streams
The NoSuchElementException exception occurs when accessing an element that doesn’t exist. Find out the best practices of avoiding it and writing robust code.
Convert File to Byte Array in Java
Filed under Java IO
Learn how to convert a file into a byte array in Java.
Get First Date of Current Month in Java
Filed under Java Dates
Learn how to obtain the first date of the current month in Java using JDK classes and third-party libraries like Joda Time.