How to return multiple values from a method
I came the following method "How do I return multiple values from a method?" posted elsewhere. The problem is that I wanted to tested the method posted, but I am getting the incorrect result. Can someone tell me how my Driver.java program [see below] should be coded?
public class UserName {
protected String ivFirstName, ivLastName;
public UserName(String first, String last) {
ivFirstName = first;
ivLastName = last;
}
public String getFirstName() {
return ivFirstName;
}
public String getLastName() {
return ivLastName;
}
}
public class User {
protected String ivFirstName = "Java";
protected String ivLastName = "Developer";
/**
* This is returning a single Object, which contains
* multiple values.
*/
public UserName getName() {
return new UserName(ivFirstName, ivLastName);
}
}
// This is my Driver.java program to test the method posted.
// The result I got was: UserName@7d8a992f
//
public class Driver {
public static void main (String[] args) {
User method = new User();
System.out.println(method.getName());
}
}
View Answers
Related Tutorials/Questions & Answers:
Advertisements
Java Method Return Multiple ValuesJava
Method Return Multiple Values
In this section we will learn about
how a
method can
return multiple values
in Java.
This example explains you
how a
multiple values can be
return by a
method.
This example explains you all
How to pass multiple values from a servlet to JSP?How to pass
multiple values from a servlet to JSP? hi, I want to pass
multiple values form a servlet to JSP.
Hw do i do that?
I am able to send one value at a time without any prb, but I am unable to carry
multiple (
from two
How to carry multiple values from a Servlet to a JSP?How to carry
multiple values from a Servlet to a JSP? By using...).
----response.sendRedirect("index.jsp?uname="+username);----
But I want
multiple values needs to be carried
from my servlet to a JSP.
How do I do
Regarding method returns multiple valuesRegarding
method returns
multiple values Hi,
1)I have a requirement like,1
method returns
multiple values.how to do that one.
2)can i use
method, for example like getFile()[] in this way or not.
plzzzzzzzzzzzzzzzzzz provide
How to return a string from a JTextFieldHow to
return a string
from a JTextField Hi,
Am new to java, and am trying to get a string
from a JTextField so that
I can compare it with another.... The problem is i have no clue
how to get the very string i need
because i think
select tag multiple values select tag
multiple values I want to insert
multiple values in database which i have selected
from select tag
@SessionAttributes multiple values@SessionAttributes
multiple values
In this section we will see
how you can use @sessionattributes to set
multiple session
values to it.
While developing... for
multiple values are:
@SessionAttributes({"formdata","
How to get Keys and Values from HashMap in Java?How to get Keys and
Values from HashMap in Java? Example program of
iterating... through keys and get the
values from a HashMap object.
The entrySet()
method... to iterate the keys and
get the
values and print on the console.
How to get keys
multiple select values multiple select
values can you provide an example for
multiple select
values for html:select tag
PHP Returning Values from FunctionReturnig
Values from function:
From a function we can
return values using optional
return statement, in PHP
we can
return arrays, objects. With the help of the
return statement the control
moves back to the calling portion
Java Method Return Value Java
Method Return Value
Java
method Return Value
return to the code when... the value within the body of
method. The
method declared void does not
return any
how to fetch values from .properties to a html filehow to fetch
values from .properties to a html file I have a .properties file with some key value pairs in it. I need to fetch the
values from this .properties file into a html file.Please let me know
how to do
How to values from xml using java?How to
values from xml using java? Hi All,
I want to read value
from following < Line> xml using java.. In < Line>,data is in format of key and value pair.. i want to read only
values..could u plz help me
How to Display values from databse into tableHow to Display
values from databse into table I want to display
values from database into table based on condition in query,
how to display... enter either bookname or authorname and click on search button the
values from how to get a values from processRecord - JSP-Servlethow to get a
values from processRecord dear sir,
i have a problem in getting a
values from java to jsp.Here jsp is used to read a excel sheet that intern call a java program so i want a column
values i.e a column contains
retrieve multiple attribute valuesXML retrieve
multiple attribute values Hello All
Am a beginner. Would like some help with this.
The following is part of my XML file:
<...;
What I would like is to retrieve both the attribute
values of process
retrieve multiple attribute valuesretrieve
multiple attribute values Hello All
Am a beginner. Would like some help with this.
The following is part of my XML file:
<process... like is to retrieve both the attribute
values of process:Output during execution
retrieve multiple attribute valuesretrieve
multiple attribute values Hello All
Am a beginner. Would like some help with this.
The following is part of my XML file:
<process... like is to retrieve both the attribute
values of process:Output during execution
How to create file from input values in Jframe ?How to create file
from input
values in Jframe ? hi i m doing my project using java desktop application in netbeans.i designed a form to get the user's academic details and on clicking the submit button,it displays all
What is the return type of the main method?What is the
return type of the main
method? hi,
What is the
return type of the main
method?
thanks
Hi,
In the java programming the Main()
method doesn't
return anything hence declared void. In Java, you need
Call an array from multiple functionsCall an array
from multiple functions I am having two methods in this
method i am getting array
values from another class.
i create same array name for accessing the
method values(array) but it will access only one
method values PHP Functions and Return valuesPHP Functions and
Return values
A function is the a block of code whom you can... need it.
To protect the script
from being auto executed on page load , we put... to the function. You
may call these function
from any where within page.
Syntax
How to call the run method from another class?How to call the run
method from another class? Sorry, if this is a stupid question.
I would like to find out
how to call the run
method... to FereastraPrincipala after introducing
values in the textfields
from PHP Return Statements. In PHP we can
return values, arrays, or object.
If the function is called
from within the function then execution will immediately stops,
return is also used...PHP Returning Statement
Values:
PHP
Return statement is used to
return a value
How to retrieve array values from html form to jsp?How to retrieve array
values from html form to jsp? Hi! I am... sample code for
how to retrive array
values from html to jsp.
hi friend... it into jsp. Means i just want to retrieve
values from html form containing array
how to pass values from 2nd page tp 3rd page....how to pass
values from 2nd page tp 3rd page.... Hi,
How to pass
values from 2nd page to 3rd page.....
here are my programs(not exactly correct...
how to get the
values(of userid)
from Login1.jsp....
plz help me
java method return type : - Java Beginnersjava
method return type : i have one question regarding methods,,, if we create a
method with
return type as class name (public employee addemp(int... int classasmethod()
{
System.out.println("classasmethod
method");
return 10
Data from multiple ResultSets?Data
from multiple ResultSets? hello,
How can I get data
from multiple ResultSets?
Hi,ADS_TO_REPLACE_1
You can iterate the ResultSet separately and get the required data.
Thanks