eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Partner – LambdaTest – NPI EA (cat= Testing)
announcement - icon

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

1. Overview

When we read others’ code, sometimes we can see some interesting and novel approaches that we’ve never seen before. Knowing what those tricks do can significantly enhance our comprehension of the codebase and encourage us to explore our viewpoints on Java programming.

In this tutorial, we’ll discuss an interesting usage in Java: -->

2. Introduction to the Problem

As usual, let’s start with an example:

int i = 6;
while ( i-->0 ) { 
    // some processing in loop 
}

At first glance, this code is pretty straightforward. A while loop executes some logic repeatedly.

However, if we take a closer look at the while statement, what does the expression i-->0 do? We may haven’t seen the usage of the --> operator before. If we search in the Java documentation, the closest operator we can find is the ‘->’ operator used in lambda expressions. But apparently, the code in the example has nothing to do with lambda expression.

So next, let’s first figure out what --> does. Then, we’ll have a short quiz for other similar tricks.

For simplicity, we’ll use unit test assertions to present variable values instead of printing them out in this tutorial.

3. Understanding -->

First of all, -->” in ( i-->0 ) isn’t a Java operator. Actually, (i-->0) is the same as (i-- >0) or the more clear format: ((i--) > 0).

Therefore, it performs two operations: post-decrementing i and the “greater than 0” check.

When we initialize the variable i with the value 6, it yields a sequence of numbers within the loop: 5, 4, 3, 2, 1, and 0. Following this sequence, i transitions to -1, causing the loop to terminate:

List<Integer> resultWhile = new ArrayList<>();
int i = 6;
while (i-- > 0) {
    resultWhile.add(i);
}
assertEquals(Lists.newArrayList(5, 4, 3, 2, 1, 0), resultWhile);

Similarly, we can use the same trick in a for-loop:

List<Integer> resultFor = new ArrayList<>();
for (int j = 6; j-- > 0; ) {
    resultFor.add(j);
}
assertEquals(Lists.newArrayList(5, 4, 3, 2, 1, 0), resultFor);

 

Now that we have a clear understanding of what --> does. Let’s explore and experiment with some similar tricks in the upcoming quiz section.

4. Quiz Time!

The quiz has four challenges.

Let’s say we have an integer list:

List<Integer> result = new ArrayList<>();

With each challenge, the integer list is reset, followed by the gradual insertion of numbers within a while loop. Our objective is to determine the numbers in the list after the loop execution.

The first challenge is about understanding ++<.

4.1. Understanding ++<

int i = -1;
while (i++<5) {
    result.add(i);
}

Similar to -->,i++<5 ‘ post-increments i and then compares i to 5. As i‘s initial value is -1, we’ll have 0 to 5 in the result:

assertEquals(Lists.newArrayList(0, 1, 2, 3, 4, 5), result);

Next, let’s interpret another expression <--.

4.2. Understanding <--

result.clear();
int j = 10;
while (0<--j) {
    result.add(j);
}

This time, as the code above shows, the post-decrement operation is changed to pre-decrement. Therefore, the loop fills 9 to 1 to the list:

assertEquals(Lists.newArrayList(9, 8, 7, 6, 5, 4, 3, 2, 1), result);

Then, let’s look at a similar expression >++.

4.3. Understanding  >++

result.clear();
int n = 0;
while (6>++n) {
    result.add(n);
}

As we can see in the code snippet, ‘6>++n’ pre-increments i and then compares to 6 in each loop step. Thus, we’ll have 1 to 5 as a result:

assertEquals(Lists.newArrayList(1, 2, 3, 4, 5), result);

Finally, let’s see a challenge that looks a bit different.

4.4. Understanding >>>=

result.clear();
int x = 32;
while ((x>>>=1)>1) {
    result.add(x);
}

This challenge is different from others. x>>>=1 has nothing to do with pre-/post-increment or pre-/post-decrement. >>> is the unsigned right-shift operator.

Therefore, x>>>1 right-shifts one place, and the result is the same as x/2. Further, x >>>=1 performs the shift operation and reassigns the result to the variable x. Thus, given x=32, the result list contains 16, 8, 4, and 2:

assertEquals(Lists.newArrayList(16, 8, 4, 2), result);

So far, we’ve gone through the challenges and understood what ‘-->‘ and similar tricks do.

5. Conclusion

In this article, we discussed what --> does in Java. Additionally, we engaged in a quiz, exploring a few similar tricks.

It’s worth noting that when using these formats, it’s advisable to insert a space or braces between the two operators. This practice enhances code readability. For instance, it’s preferable to write i-- > 0 or (i--) > 0 instead of i-->0.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)
2 Comments
Oldest
Newest
Inline Feedbacks
View all comments