- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Pass an integer by reference in Java
To pass an integer by reference in Java, try the following code −
Example
public class Demo { public static void display(int[] arr) { arr[0] = arr[0] + 50;; } public static void main(String[] args) { int val = 50; int[] myArr = { val }; display(myArr); System.out.println(myArr[0]); } }
Output
100
In the above program, a custom method is created, which pass an int array.
int val = 50; int[] myArr = { val }; display(myArr);
In the method, we have performed mathematical operation on the value of array.
public static void display(int[] arr) { arr[0] = arr[0] + 50;; }
The updated value is then displayed in the main.
System.out.println(myArr[0]);
- Related Articles
- Pass by reference vs Pass by Value in java
- Is java pass by reference or pass by value?
- How to pass an array by reference in C++
- Describe pass by value and pass by reference in JavaScript?
- What is Pass By Reference and Pass By Value in PHP?
- Differences between pass by value and pass by reference in C++
- Pass by reference vs value in Python
- Is JavaScript a pass-by-reference or pass-by-value language?
- What is pass by reference in C language?
- Which one is better in between pass by value or pass by reference in C++?
- How to pass arguments by reference in Python function?
- Why do we pass a Pointer by Reference in C++?
- How to pass arguments by reference in a Python function?
- How do you pass objects by reference in PHP 5?
- How do we pass parameters by reference in a C# method?

Advertisements