The NoSuchElementException exception occurs when accessing an element that doesn’t exist. Find out the best practices of avoiding it and writing robust code.
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
- Java String (7)
- Java Dates (5)
- Java (4)
- Spring Boot (3)
- Java IO (3)
- Spring Web (2)
- Spring MVC (2)
- Spring Data (2)
- Jackson (2)
- Spring Persistence (1)
- Spring (1)
- REST (1)
- Programming (1)
- Persistence (1)
- Java Streams (1)
- Java Map (1)
- Java Array (1)
- JSON (1)
- HTTP Client-Side (1)
Learn how to convert a file into a byte array in Java.
Learn how to obtain the first date of the current month in Java using JDK classes and third-party libraries like Joda Time.
Learn how to check if a string contains a number in Java.
Learn how to capitalize the initial character of each word in a Java string.
Explore how to convert a char array to an int array in Java.
Explore several ways to convert a HashMap to an ArrayList in Java.
Learn how to easily get yesterday’s date in Java.
Discover how to find the last day of a month in Java using both core Java methods and popular libraries. This article provides step-by-step explanations for accomplishing the task using Date and Calendar classes, Java 8’s Date Time API, and the Joda Time library with code examples and test cases.
In this short tutorial, we discuss various methods of adding one month to the current date in Java. We cover using core Java methods as well as popular external libraries such as Joda-Time and Apache Commons Lang3.
This article delves into the similarities and differences between the findBy and findOneBy prefixes in Spring Data JPA. It explores the concept of derived query methods, provides code examples, and explains the exception thrown by findBy queries when the result size doesn’t match expectations.
In this tutorial, we’ll explore handling the ‘NoSuchElementException: No line found’ exception when reading a file using the Scanner class in Java. We’ll explain its root cause and present three solutions: defensive programming, exception handling, and checking file emptiness.
This article delves into the difference between the next() and nextLine() methods of the Scanner class.The article also covers the use of custom delimiters and provides code examples for better understanding. Understanding these distinctions enables developers to parse input effectively using Scanner.
This article provides several ways of converting a PrintStream to a String in Java.The approaches include using ByteArrayOutputStream, a custom output stream, and Apache Commons IO.
This tutorial explains the exception org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement expected “identifier”. It provides a practical example to reproduce the exception and showcases how to fix it by double-quoting the keyword or using a JDBC URL workaround. It also covers how to automatically quote all database identifiers when using Hibernate.
This tutorial explains different ways to check if the first character of a string is a number in Java. It covers using charAt(), Character.isDigit(), Pattern class, and matches() method. It also demonstrates how to use Guava’s CharMatcher utility class to accomplish the same objective.
Learn how to fix a common JsonMappingException when deserializing a JSON string.
This article explains how to fix the “PropertyReferenceException: No property found for type” in Spring Data JPA. It advises using exact property names when defining query methods to avoid the exception. Practical examples are provided.
Explanation of the reason behind EmptyResultDataAccessException when jdbcTemplate is used and how to fix it.
Why IllegalArgumentException is thrown and how to fix in it in Java.
A reminder of what an anonymous class is and how to convert it to a lambda expression.
Explore different ways to implement case-insensitive enum mapping in Spring Boot.
Learn how to compare characters in Java.
Learn how to truncate a String in Java.
Learn two different ways to format an instant as a string – one using core Java and the other using the Joda-Time library.
Learn what causes Spring to throw HttpMessageNotWritableException with the message “No converter for [class …] with preset Content-Type” and how to solve it.
Learn how to check if a String ends in a certain pattern in Java using core Java methods as well as Apache Commons Lang’s StringUtils class.
Learn several ways to split a string after every n characters in Java.
Learn how to solve the ApplicationContextException in Spring Boot.
Learn about Spring’s HttpMessageNotWritableException: “No converter found for return value of type” exception.
Learn about Spring’s RestTemplate Not enough variables available to expand IllegalArgumentException.
Learn about file access management in Java
Learn how to send JSON parameters in GET and POST requests when using Spring MVC.
Learn all about the Spring @ConditionalOnProperty annotation.