Implement MutableInt Class in Java

In this post, we will discuss how to implement MutableInt Class in Java which is a mutable wrapper over primitive int. We will also take a look at MutableInt Class provided by Apache Commons Library.


 

1. Custom Implementation

Below is custom java implementation of MutableInt class having several utility methods. The advantage of custom implementation over third-party libs is that we can easily add more methods as per the requirement.

 

Download   Run Code

Output:

6

 

2. Apache Commons Lang

Apache Commons Lang also provides implementation of the MutableInt class. The basic usage is demonstrated below:

 

Download

Output:

1

 
Thanks for reading.

Please use our online compiler to post code in comments.
Like us? Please spread the word and help us grow. Happy coding 🙂
 



Leave a Reply

avatar
  Subscribe  
Notify of