my dog learned polymorphism
The moose likes Beginning Java and the fly likes returning multiple types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "returning multiple types" Watch "returning multiple types" New topic

returning multiple types

Gamb Rockwell

Joined: Dec 09, 2003
Posts: 25
I need to return multiple values of different types from a java method. What is the best way that I should use to achieve that.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

Define a new class with member variables to hold all the values. Have your method return an instance of this new class with the members initialized to the values you want to return.

[Jess in Action][AskingGoodQuestions]
Fisher Daniel
Ranch Hand

Joined: Sep 14, 2001
Posts: 582
I sometimes using array of Object (Object[]) to store multiple data type in return of method...

By the way, I dont know whether it is a bad design or not...

Correct me if I am wrong
Hope this helps
Guy Allard
Ranch Hand

Joined: Nov 24, 2000
Posts: 776
I use List rather than an array of Object.

Just a thought.

I agree. Here's the link:
subject: returning multiple types
It's not a secret anymore!