Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
How to return 2 values from a Java method
A method can give multiple values if we pass an object to the method and then modifies its values. See the example below −
Example
public class Tester {
public static void main(String[] args) {
Model model = new Model();
model.data1 = 1;
model.data2 = 2;
System.out.println(model.data1 + ", " + model.data2);
changeValues(model);
System.out.println(model.data1 + ", " + model.data2);
}
public static void changeValues(Model model) {
model.data1 = 100;
model.data2 = 200;
}
}
class Model {
int data1;
int data2;
}
Output
1, 2 100, 200
Advertisements
