Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: can i return two values from a return method?

  1. #1
    Junior Member tonu's Avatar
    Join Date
    Dec 2013
    Posts
    9
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default can i return two values from a return method?

    can i return two values from a return method?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,094
    Thanks
    48
    Thanked 2,152 Times in 2,125 Posts

    Default Re: can i return two values from a return method?

    No. The return statement can only specify one value to be returned.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member andbin's Avatar
    Join Date
    Dec 2013
    Location
    Italy
    Posts
    443
    Thanks
    4
    Thanked 122 Times in 114 Posts

    Default Re: can i return two values from a return method?

    Quote Originally Posted by tonu View Post
    can i return two values from a return method?
    A method can return only one value of one type. But it can be an object (with more properties) or an array (with more elements).
    But apart this, you should clarify why and for what you need to return two values. Are they related? (e.g. the min and max of something) Do you think it has sense that these two values be modeled with an object?
    Andrea, www.andbin.net SCJP 5 (91%) SCWCD 5 (94%)

    Useful links for Java beginners My new project Java Examples on Google Code

  4. #4
    Junior Member
    Join Date
    Dec 2013
    Posts
    7
    My Mood
    Cheerful
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: can i return two values from a return method?

    Quote Originally Posted by andbin View Post
    A method can return only one value of one type. But it can be an object (with more properties) or an array (with more elements).
    But apart this, you should clarify why and for what you need to return two values. Are they related? (e.g. the min and max of something) Do you think it has sense that these two values be modeled with an object?
    Yes, use object (with many fields) or List Object.

  5. #5
    Junior Member lyhung009's Avatar
    Join Date
    Jan 2014
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: can i return two values from a return method?

    Please create an object then save all informations into its instance and return it.
    Always read, always write, can not stop learning! I'm willing to answer your question.

Similar Threads

  1. Methods with parameters and return values help
    By andrag3k in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 15th, 2013, 09:37 PM
  2. Replies: 1
    Last Post: July 29th, 2013, 06:22 AM
  3. What is wrong with function return values
    By Shivafeb17 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 20th, 2013, 09:55 PM
  4. [SOLVED] Return all values in an ArrayList from a method
    By IanSawyer in forum Collections and Generics
    Replies: 1
    Last Post: March 28th, 2012, 09:53 AM
  5. Need help my values wont return
    By sajeed in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 7th, 2012, 07:46 AM

Tags for this Thread