Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,907 questions

51,839 answers

573 users

How to return multiple values from a method in Java

3 Answers

0 votes
public class MyClass {
    public static int[] m() { 
        int[] arr = new int[3]; 
        
        arr[0] = 23; 
        arr[1] = 9; 
        arr[2] = 983; 
                
        return arr; 
    } 
    public static void main(String args[]) {
        int[] result =  m(); 
          
        System.out.println(result[0]);
        System.out.println(result[1]);
        System.out.println(result[2]);
    }
}
 
 
 
/*
run:
 
23
9
983
 
*/

 



answered Aug 8, 2019 by avibootz
0 votes
final class Test
{
    public String s;
    public int i;
    public char ch;
 
    public Test(String s, int i, char ch) {
        this.s = s;
        this.i = i;
        this.ch = ch;
    }
}
 
public class MyClass
{
    public static Test getDetails() {
        String s = "Java";
        int i = 84672;
        char ch = 'z';
 
        return new Test(s, i, ch);
    }
 
    public static void main(String[] args)
    {
        Test test = getDetails();
 
        System.out.println(test.s);
        System.out.println(test.i);
        System.out.println(test.ch);
    }
}




/*
run:

Java
84672
z

*/

 



answered Jun 11, 2021 by avibootz
0 votes
import java.util.List;
import java.util.Arrays;

public class MyClass {
    public static List<Object> m() {
        String s = "Java";
        int n = 23876;
        char ch = 'z';
  
        return Arrays.asList(s, n, ch);
    }
    public static void main(String args[]) {
        List<Object> list = m();
        
        System.out.println(list);
    }
}
  
  
  
/*
run:
  
[Java, 23876, z]
  
*/

 



answered Jan 3, 2022 by avibootz

Related questions

3 answers 285 views
3 answers 327 views
3 answers 123 views
1 answer 100 views
1 answer 88 views
1 answer 129 views
129 views asked Jul 25, 2019 by avibootz
...