Can a method return multiple items

Can a method return more than one thing?
I want to have a method return a boolean and a String. My method is saying if something is right or wrong, then its saying the reason why.
help, please.
Thanx

Afternoon_Delight wrote:
My question is:
Is there a way so that it can be more like this:
public boolean, String checkValidity (){
To expand on the previous posts, one way (not saying it's the best one!) is to create an object that combines the information that you want returned:
public class MyValid
  private boolean valid;
  private String text;
  public MyValid(boolean valid, String text)
    this.valid = valid;
    this.text = text;
  public boolean isValid()
    return valid;
  public String getText()
    return text;
class DoFoo
  public MyValid checkValidity()
    return new MyValid(false, "Because I said so!");
}

Similar Messages

  • Can java method return  multiple values

    hey , I need big favor can i return two arrays in a single function

    Not directly no.
    But there are ways around it.
    You can create a "result object" which has attributes being the two arrays, and return that object (ie wrap the arrays in another object)
    You could put the arrays into a collection (eg ArrayList/Vector) and then return that object. You can then retrieve the two arrays as the first two items in that list.
    Either of those should work, even if they are hacks ;-)
    Cheers,
    evnafets

  • Can a method return a class ?

    hi,
    i have a simple question.
    can a method return class value ?
    in the below script i did'nt understand the commented line.
    package com.google.gwt.sample.stockwatcher.client;
    import com.google.gwt.user.client.rpc.RemoteService;
    import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
    @RemoteServiceRelativePath("login")
    public interface LoginService extends RemoteService {
      public LoginInfo login(String requestUri);  //What is this ? is this a sample of what i asked ?
    }

    The answer to your question is yes.
    The idea is that an object calls a function of another object (passing in objects to the function as arguments) in which that object returns an object (note the arguments or returned value of the function may alternately be primitive types). Each object typically encapsulates data and provides a rich set of functions to the calling object so that calling object doesn't have to deal with the raw data directly. Therefore, not only does the calling object get the data it wants, but also a rich set of functions that can manipulate that data.
    Example:
    Book book = new Book();
    int characterCount = book.getChapter(3).getParagraph(4).getSentence(12).getWord(8).getCharacterCount();
    In the above, each object (Book, Chapter,Paragraph,Sentence,Word) has a rich set of functions it provides to its caller.
    Example: the Sentence Object has a collection of word objects (raw data). Functions it provides to Paragraph object are:
    Word getWord(int index), Words getWords(), int getWordCount().
    If you haven't already done so, I suggest reading a book on Java from cover to cover to pick up such Object Oriented concepts.

  • Find(String pkey) method returns multiple object of the same row

    I'm not quite sure what i've done or havent done, but I've implemented updating a row using the em.persist(Object) method.....works great, but after i did that a few times the find(String pkey) method returns multiple copies of 1 row in the db
    here are two rows in the db
    personid(PK) firstName lastName
    1234 joe jones
    2345 rachel jones
    when i execute any query looking for people with the last name jones, ie
    select object(p) from Person p where p.lastName='jones'
    it returns multiple objects of each row ie
    1234 joe jones
    1234 joe jones
    1234 joe jones
    1234 joe jones
    2345 rachel jones
    2345 rachel jones
    2345 rachel jones
    2345 rachel jones
    There is only one row for both rachel and joe in the db, but why is the entity manager returning multiple objects of each, and how do i prevent that without using DISTINCT?
    Thanks for the help in advance

    Sorry, i forgot to mention i'm using ejb 3 and jboss

  • Best method - update multiple items

    Hello all. I have 2 tables. One called deposits and another called items. 1 deposit can have 1 or many items.
    Hence the item table looks like this
    |  item_num      |  item_name     |   deposit_id    |
    |       1        |   bike         |          1      |
    |       2        |   helmet       |          1      |
    |       3        |   bike         |          2      |
    -----------------------------------------------------Now, I would like to update deposit 1. I would like to remove helmet from the deposit. The way I figure to do it is to do the following:
    1) Remove all items where deposit id = 1
    2) Add new items found in text area and set their deposit id to 1.
    Would this be the correct way to do it? Update ??

    Nah, its a bit awkard, or perhaps my brain matter isn't dense enough to get it :D
    I could delete multiple items from a text area.
    ie before the text area may look like this:
    bike
    helmet
    gloves
    lights
    Then after the update it may look like
    bike
    bike
    gloves
    I opted for the delete all then re-inputted the answers. Thanks for your response anyway Eric H.

  • Why can I not select multiple items in Muse using Shift Click after installing update?

    I am trying to select multiple items on a Muse page by holding shift and clicking each items. This has been pretty much my standard method across Adobe products but after updating Muse it will no longer let me do this. Am I missing something or did this method change with the update?

    It seems to be happening mostly for Hotmail account.  I just rebooted and tested two accounts.  Only in Hotmail now.

  • Can "main" method return values

    Hi,
    I have a requirement of returning values to the
    command prompt from the main method. Is this possible
    to do in the first place. Is it valid.
    i.e. Can you do the following in Java,
    =======================================
    import java.io.*;
    import java.lang.Object;
    import java.util.*;
    public class P
         public static String main(String args[])
         String bye = "BYE";
         return(bye);
    =========================================
    Can "main" method in Java return values at command
    prompt.
    Can you have something like,
    public static String main(String args[])
    instead of
    public static void main(String args[])
    Help urgently needed as I need to pipe data from a
    Java program to a C++ program. One method is to
    writing to a flat file but this would cause overheads
    reading and writing to a file, hence this way.
    Any help would be greatly appreciated.
    Thanks in advance.
    Thank,s

    Hi jchak,
    Yes I am trying to pass a Java String to a C++
    application. Any insights, any help.
    OK the whole thing goes as follows,
    =========================================
    Theres a C++ application which first starts up.
    This app is then supposed to invoke a Java class file
    which does some processing. Finally the value of one
    variable in Java (actually a huge String) is to be made
    available back to C++. This could be done thru flat file
    wherein the Java outputs the string to the flat file
    and on return the C++ program can be made to read the
    same flat file to retrieve that string but this would
    surely cause some overheads (time factor) reading and
    writing files. So I wish to devise some way by means
    of which I can return the string value back to the C++
    program. Piping of data from one app to another is what I
    want to do.
    Is there some way by means of which Java can return
    back or communicate or pipe back the string back to
    C++. How can it be done without using external flat files
    or databases.
    Thansk,
    JAtin

  • Returning multiple items

    I am working on a script that does extensive logging, both to the console and to a log file. For a number of reasons I have adopted a logging mechanism of adding to a logging array and then periodically pushing the array to the logging function for processing.
    Now I have a function that when successful will return a string. But there are a number of places where an error could happen, and I want to evaluate all of them and return all failures, rather than have users need to fix one thing, run the script, find
    a new thing and fix it, run the script... So, when there is an error I need to return an array, which I can then append to the array in the calling function. And when successful I return the string.
    My question is, am I better off returning both the string and the array, which I think I read can be done. Or returning one or the other, and the calling function has to test the returned value for type to determine if the call was successful or not? Or
    is there maybe an even better approach? My other thought, which I had as I typed, is to return an object, with a string member and an array member. Curious if I am on the right track with that late night thought.
    Thanks!

    I agree with Al, that you have a lot of questions and we really aren't able to give you advice on how to structure your script.
    That being said, this is something I've done for long script logging.  I'm sure there are better ways to do it, and some or none of this may help you or be useful/meaningful/appropriate for your project, but it will give you a an object with error and
    success that you can sort and evaluate as you see fit.  
    In some ways this is probably reinventing the wheel, YMMV.  It's been useful to me.
    $FileName = $MyInvocation.MyCommand.Name
    $LogFile = ".\$($FileName -replace '\.ps1')_Log.csv"
    If (Test-Path $LogFile){
    $i=0
    While (Test-Path "$($LogFile -replace '\.csv')_v$i.log") {$i++}
    Rename-Item $LogFile "$($LogFile -replace '\.csv')_v$i.csv"
    $LogObject = @{}
    $Error.clear()
    Function Log-Info ($LogType, $LogData) {
    $LogElement = New-Object PSObject -property @{Type=$LogType;Data=$LogData;Time=((Get-Date).ToString())}
    $LogElement | Export-CSV $LogFile -Append
    $LogObject += $LogElement
    <#
    Do Something {
    Check if something happened
    If (successful) { Log-Info "Success" "Do Something Succeded" }
    Else (failed/Error) { Log-Info "Error" "Do Something didn't" }
    #>
    <#
    Try {
    Do something else
    Log-Info "Success" "Something else succeded"
    } Catch {
    Log-Info "Error" "Something else failed"
    #>
    # catch anything I didn't plan for
    if ($Error.count -ne 0) {
    for ($i=$Error.Count-1; $i -ge 0;$i--) {
    Log-Info "Error" @($Error[$i].Exception.Message)
    I hope this post has helped!

  • Can a method return more than one value?

    I was studying for my biology exam and I got bored and I started thinking and then I wandered if a method can return more than one value...?
    For example, if I want a method to return a row a column, I make a method that returns an int. But what if I want to return two ints? Or what If I want to return an integer and a string? Is it possible or do I have make two methods, each returning one thing?
    What I always did until now is is I want for example to return a few integers, I would store them in a String and then when I return the string, I parse the numbers out using stringtokenizer... but it doesn't look like the best way... and it's pretty annoying...

    I'm weak on terminology, hence I don't even know what
    AFAIK means...As Far As I Know
    This doesn't really make sense for me. It's more
    efficient to make a whole class just for two
    integers, than having two methods? Efficiency is not the point. The flow is.
    If you have two methods, the caller must be aware of both of them. The other way it's up to the callee.
    Just because the
    two integers are related to each other? Doesn't
    making a class require more memory usage than just
    making two one-line methods?The memory usage is not wholly irrelevant, but there are ways to handle that (caching, inlining, etc.).
    It's a bit hard to counter your point for me, but if you had done a lot of GUI painting stuff, you'd see all those Points, Dimensions, Rectangles, you name it, are quite invaluable.

  • Return Multiple Items with One Lookup Value

    Hi there,
    Within my data set there are multiple values that I would like to return into a different table.
    For example:
    In the "players from australia" table I would like to search the main data set for the "AUS" tag in column B and then automatically display the names of those players.
    There was something similar posted a few days ago Search sheet and return associated values for multiple matches and I tried to apply those formulas to my data but it didn't work...perhaps slightly different application of the function.
    fyi: the "category" table is simply to add up the number of players from each country and return a numerical value, as opposed to the names. I also use it as the cell from which to determine which value to search and display, i.e. A2 for the AUS players to be displayed in the empty table.
    Any help would be greatly appreciated!!
    Ed.

    You could try something like this:
    The formula in the Index column, copied down:
         =B2&COUNTIF(B$1:B2,B2)
    The formula in A2 of the Players From table, copied down and right:
        =INDEX(Table 1::$A,MATCH(A$1&ROW()−1,Table 1::$D,0),)
    To suppress the display of the red warning triangles, you can wrap that in IFERROR, like this:
         =IFERROR(INDEX(Table 1::$A,MATCH(A$1&ROW()−1,Table 1::$D,0),),"")
    This takes the value in row 1, appends the row number it's on less 1, and uses MATCH to find what row contains that value in the Index column of the other table. That row number is fed to INDEX, which returns the value from column A.
    SG

  • Can EJB method return another EJB?

    Hello,
    I am new to EJB technology. I am working with Sun Application Server bundled in Netbeans 4.1
    Is it po[b]ssible a method of a session bean to return another EJB which is instantiated with arguments depended on the method?
    If no, is there an alternative way?
    thank you in advance, Kostas

    Is it possible within the SessionBean method to
    call another Session Bean, create it using the
    local interface, pass some parameters using setter
    methods, then cast it from local interface to
    remote and send it to the user?I think it's not possible casing Local Interface into Remote Intrface, because they inherit from different classes.
    Remote interface extends EJBObject and Local interface extends EJBLocalObject
    Fil

  • [UIX] How To: Return multiple values from a LOV

    Hi gang
    I've been receiving a number of queries via email on how to return multiple items from a LOV using UIX thanks to earlier posts of mine on OTN. I'm unfortunately aware my previous posts on this are not that clear thanks to the nature of the forums Q&A type approach. So I thought I'd write one clear post, and then direct any queries to it from now on to save me time.
    Following is my solution to this problem. Please note it's just one method of many in skinning a cat. It's my understanding via chatting to Oracle employees that LOVs are to be changed in a future release of JDeveloper to be more like Oracle Forms LOVs, so my skinning skills may be rather bloody & crude very soon (already?).
    I'll base my example on the hr schema supplied with the standard RDBMS install.
    Say we have an UIX input-form screen to modify an employees record. The employees record has a department_id field and a fk to the departments table. Our requirement is to build a LOV for the department_id field such that we can link the employees record to any department_id in the database. In turn we want the department_name shown on the employees input form, so this must be returned via the LOV too.
    To meet this requirement follow these steps:
    1) In your ADF BC model project, create 2 EOs for employees and departments.
    2) Also in your model, create 2 VOs for the same EOs.
    3) Open your employees VO and create a new attribute DepartmentName. Check “selected in query”. In expressions type “(SELECT dept.department_name FROM departments dept WHERE dept.department_id = employees.department_id)”. Check Updateable “always”.
    4) Create a new empty UIX page in your ViewController project called editEmployees.uix.
    5) From the data control palette, drag and drop EmployeesView1 as an input-form. Notice that the new field DepartmentName is also included in the input-form.
    6) As the DepartmentName will be populated either from querying existing employees records, or via the LOV, disable the field as the user should not have the ability to edit it.
    7) Select the DepartmentId field and delete it. In the UI Model window delete the DepartmentId binding.
    8) From the data controls palette, drag and drop the DepartmentId field as a messageLovInput onto your page. Note in your application navigator a new UIX page lovWindow0.uix (or similar) has been created for you.
    9) While the lovWindow0.uix is still in italics (before you save it), rename the file to departmentsLov.uix.
    10) Back in your editEmployees.uix page, your messageLovInput source will look like the following:
    <messageLovInput
        model="${bindings.DepartmentId}"
        id="${bindings.DepartmentId.path}"
        destination="lovWindow0.uix"/>Change it to be:
    <messageLovInput
        model="${bindings.DepartmentId}"
        id="DepartmentId"
        destination="departmentsLov.uix"
        partialRenderMode="multiple"
        partialTargets="_uixState DepartmentName"/>11) Also change your DepartmentName source to look like the following:
    <messageTextInput
        id=”DepartmentName”
        model="${bindings.DepartmentName}"
        columns="10"
        disabled="true"/>12) Open your departmentsLov.uix page.
    13) In the data control palette, drag and drop the DepartmentId field of the DepartmentView1 as a LovTable into the Results area on your page.
    14) Notice in the UI Model window that the 3 binding controls have been created for you, an iterator, a range and a binding for DepartmentId.
    15) Right click on the DepartmentsLovUIModel node in the UI Model window, then create binding, display, and finally attribute. The attribute binding editor will pop up. In the select-an-iterator drop down select the DepartmentsView1Iterator. Now select DepartmentName in the attribute list and then the ok button.
    16) Note in the UI Model you now have a new binding called DCDefaultControl. Select this, and in the property palette change the Id to DepartmentName.
    17) View the LOV page’s source, and change the lovUpdate event as follows:
    <event name="lovSelect">
        <compound>
            <set value="${bindings.DepartmentId.inputValue}" target="${sessionScope}" property="MyAppDepartmentId" />
            <set value="${bindings.DepartmentName.inputValue}" target="${sessionScope}" property="MyAppDepartmentName" />
        </compound>
    </event>18) Return to editEmployees.uix source, and modify the lovUpdate event to look as follows:
    <event name="lovUpdate">
        <compound>
            <set value="${sessionScope.MyAppDepartmentId}" target="${bindings.DepartmentId}" property="inputValue"/>
            <set value="${sessionScope.MyAppDepartmentName}" target="${bindings.DepartmentName}" property="inputValue"/>     
        </compound>
    </event>That’s it. Now when you select a value in your LOV, it will return 2 (multiple!) values.
    A couple things to note:
    1) In the messageLovInput id field we don’t use the “.path” notation. This is mechanism for returning 1 value from the LOV and is useless for us.
    2) Again in the messageLovInput we supply “_uixState” as an entry in the partialTargets.
    3) We are relying on partial-page-refresh functionality to update multiple items on the screen.
    I’m not going to take the time out to explain these 3 points, but it’s worthwhile you learning more about them, especially the last 2, as a separate exercise.
    One other useful thing to do is, in your messageLovInput, include as a last entry in the partialTargets list “MessageBox”. In turn locate the messageBox control on your page (if any), and supply an id=”MessageBox”. This will allow the LOV to place any errors raised in the MessageBox and show them to the user.
    I hope this works for you :)
    Cheers,
    CM.

    Thanks Chris,
    It took me some time to find the information I needed, how to use return multiple values from a LOV popup window, then I found your post and all problems were solved. Its working perfectly, well, almost perfectly.
    Im always fighting with ADF-UIX, it never does the thing that I expect it to do, I guess its because I have a hard time letting go of the total control you have as a developer and let the framework take care of a few things.
    Anyway, I'm using your example to fill 5 fields at once, one of the fields being a messageChoice (a list with countries) with a LOV to a lookup table (id , country).
    I return the countryId from the popup LOV window, that works great, but it doesn't set the correct value in my messageChoice . I think its because its using the CountryId for the listbox index.
    So how can I select the correct value inside my messageChoice? Come to think of it, I dont realy think its LOV related...
    Can someone help me out out here?
    Kind regards
    Ido

  • Problem with database control returning multiple rows as Array  using Oracle

    Has anybody using Oracle gotten a Database control that
    returns multiple rows to work returning an array?
    The only way I can seem to return multiple rows is by returning
    a RowSet. Returning an array gives me a NullPointerException
    (when called within a pageFlow). When calling a database control
    that returns an array from a web service I get a
    "java.sql.SQLException: ResultSet has no more data." error.
    The samples using the pointbase database seem to work, but when I
    converted the CustomerDBClient web service to use Oracle, it starts
    failing on calling the database control that returns an array
    with: "java.sql.SQLException: ResultSet has no more data."
    Has anybody gotten this to work using Oracle?
    I'm also having some problem returning an Iterator. It seems
    to work when called from a web service, but returns nothing
    if called from a page flow.
    I'm using Oracle 8.1.7 and WebLogic 8.1.
    Eric

    Do you need a particular service pack installed to return an array of custom object?
    I am getting a ResultSet contained no data error when trying.
    Thanks,
    -Thomas
    "Robin Karlin" <[email protected]> wrote:
    >
    Eddie O'Neil <[email protected]> wrote:
    All--
    Unfortunately, returning an Iterator to a JPF (or JSP) from a
    database control is broken in WLW 8.1, though it will work inside of
    a
    JWS or JCS.
    There shouldn't be a problem with returning an array of objects out
    of Oracle to the JPF, and if you need an Iterator specifically, youcan
    wrap the array in an Iterator implementation.
    Sorry for the inconvenience.
    Eddie
    Lenny wrote:
    I have gotten it to work on Oracle using Array:)
    However, I haven't gotten it to work on Oracle using Iterator:( Itis so
    simple, but doesn't work:(
    "Eric Dokken" <[email protected]> wrote in message
    news:[email protected]...
    Has anybody using Oracle gotten a Database control that
    returns multiple rows to work returning an array?
    The only way I can seem to return multiple rows is by returning
    a RowSet. Returning an array gives me a NullPointerException
    (when called within a pageFlow). When calling a database control
    that returns an array from a web service I get a
    "java.sql.SQLException: ResultSet has no more data." error.
    The samples using the pointbase database seem to work, but when I
    converted the CustomerDBClient web service to use Oracle, it starts
    failing on calling the database control that returns an array
    with: "java.sql.SQLException: ResultSet has no more data."
    Has anybody gotten this to work using Oracle?
    I'm also having some problem returning an Iterator. It seems
    to work when called from a web service, but returns nothing
    if called from a page flow.
    I'm using Oracle 8.1.7 and WebLogic 8.1.
    Eric
    I get the same error that Eric reported when trying to return an Array
    of objects.
    It is really frustrating because I can't use much of the built-in control
    logic
    that WLW provides. All I did was create a data pool for Oracle and a
    datasource.
    I modified the sample app in C:\bea81\weblogic81\samples\workshop\SamplesApp\WebApp\callJavaControl
    to point to that datasource and I get the error that Eric reports above.
    Can
    anyone help me out????
    Thanks,
    Robin

  • Submit multiple item without "Repeating table"

    Hi
    How can I do submit multiple item in list with single infopath form without repeating table?

    Create a workflow and create items with what ever information you want.
    Regards, Kapil ***Please mark answer as Helpful or Answered after consideration***

  • Return multiple values from a web method??

    Hi,
    I am wondering if it's possible for a web method to return multiple values to a client. I know each web method can return only one value of a given data type. I am looking for something like ref or out keyword in C#. If it's not available, is there any workaround? Thanks.
    Regards

    Java web service endpoints can return multiple values by using the javax.xml.rpc.holders classes. The following post might help:
    http://forum.java.sun.com/thread.jspa?threadID=684916
    If you'll be returning lots of values, it might be worth considering a document-style implementation rather than RPC-style.

Maybe you are looking for