What Is += Addition Assignment Operator In Java? - DigitalOcean
Maybe your like
- Blog
- Docs
- Get Support
- Contact Sales
- Tutorials
- Questions
- Product Docs
- Cloud Chats
- Search Community
Report this
What is the reason for this report?This undefined is spamThis undefined is offensiveThis undefined is off-topicThis undefined is otherSubmitTable of contents
- Incrementing Values With the Operator
- Using in Java Loops
- Working with multiple data types
- String Concatenation
- Conclusion
- Tutorials
- Java
- What is += Addition Assignment Operator in Java?
By Jayant Verma
Table of contentsPopular topicsIt’s the Addition assignment operator. Let’s understand the += operator in Java and learn to use it for our day to day programming.
x += y in Java is the same as x = x + y.
It is a compound assignment operator. Most commonly used for incrementing the value of a variable since x++ only increments the value by one.
Incrementing Values With the += Operator
This code will increase the value of a by 2. Let’s see the examples:
int a = 1; a+=2; System.out.println(a);
On the other hand if we use a++:
int a = 1; a++; System.out.println(a);
The value of a is increased by just 1.
Using += in Java Loops
The += operator can also be used with for loop:
for(int i=0;i<10;i+=2) { System.out.println(i); }
The value of i is incremented by 2 at each iteration.
Working with multiple data types
Another interesting thing to note is that adding int to double using the regular addition expression would give an error in Java.
int a = 1; a = a + 1.1; // Gives error a += 1.1; System.out.println(a);The first line here gives an error as int can’t be added to a double.
Output:
error: incompatible types: possible lossy conversion from double to int a = a + 1.1; // Gives errorHowever, when using the += operator in Java, the addition works fine as Java now converts the double to an integer value and adds it as 1. Here’s the output when the code is run with only the += operator addition.

E1 op= E2 is equivalent to E1 = (T) ((E1) op (E2)), where T is the type of E1, except that E1 is evaluated only once. This is Java doing typecasting to add the two numbers.
String Concatenation
The += operator also works for string mutation.
String a = "Hello"; a+="World"; System.out.println(a);
The string “Hello” has been mutated and the string “World” has been concatenated to it.
Conclusion
The += is an important assignment operator. It is most commonly used with loops. The same assignment also works with other operators like -=, *=, /=.
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
Learn more about our products
About the author
Still looking for an answer?
Ask a questionSearch for more helpWas this helpful?YesNoComments(0)Follow-up questions(0)
This work is licensed under a Creative Commons Attribution-NonCommercial- ShareAlike 4.0 International License.Deploy on DigitalOcean
Click below to sign up for DigitalOcean's virtual machines, Databases, and AIML products.Sign upPopular Topics
- AI/ML
- Ubuntu
- Linux Basics
- JavaScript
- Python
- MySQL
- Docker
- Kubernetes
- All tutorials
- Talk to an expert
Featured tutorials
- SOLID Design Principles Explained: Building Better Software Architecture
- How To Remove Docker Images, Containers, and Volumes
- How to Create a MySQL User and Grant Privileges (Step-by-Step)
- All tutorials
- All topic tags
Join the Tech Talk
Success! Thank you! Please check your email for further details.Please complete your information!
Become a contributor for community
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Sign Up
DigitalOcean Documentation
Full documentation for every DigitalOcean product.
Learn more
Resources for startups and SMBs
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Learn more
Get our newsletter
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
SubmitSubmitNew accounts only. By submitting your email you agree to our Privacy Policy
The developer cloud
Scale up as you grow — whether you're running one virtual machine or ten thousand.
View all productsGet started for free
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
Get started*This promotional offer applies to new accounts only.
© 2025 DigitalOcean, LLC.Sitemap.Tag » What Does The Mean In Java
-
Java - Basic Operators - Tutorialspoint
-
What Does % Mean In Java? - Quora
-
What Does "?" Mean In Java? - Ternary Operator - Stack Overflow
-
What Does :: Mean In Java? - Tech With Maddy
-
What's The Meaning Of 'T' In Java? - Tech With Maddy
-
What Does ! Mean In Java With Examples
-
Java Operators - W3Schools
-
What Does This Mean In Java? - Linux Hint
-
What Does @ Means In Java?? | Sololearn: Learn To Code For FREE!
-
Java Basics - Java Programming Tutorial
-
Double Colon (::) Operator In Java - GeeksforGeeks
-
A Java Symbol Decoder
-
What Is Java? - Definition From Techopedia