Re: Passing NULL Objects



shawnews wrote:
"fb" <fb@xxxxxxxxx> wrote in message
news:wsAaf.402999$tl2.182196@xxxxxxxxxxx

Hello everyone.  I have the following:

//Perform a search for the account number
public BankAccount searchAccounts (Vector<BankAccount> bankAccounts ,
long accountNumber){
  int accNum=0;
  for(int x=0;x<bankAccounts.size();x++){
    if(bankAccounts.elementAt(x) == accountNumber){
      return ??  //I want to return the object that matches from the
Vector to the calling function
    else
      return ??  //How do I return a NULL object (The reason is that I
can test for it in the returning function)
  }


So...returning null objects. Any thoughts? :-)


to return a null object:
    return null;  //easy, eh?

Indeed. I overthought the process. Thank you.


but this line: if(bankAccounts.elementAt(x) == accountNumber) will never evaluate to true because a BankAccount is not a long

perhaps you meant something like:
     if(bankAccounts.elementAt(x).getAccountNumber() == accountNumber) ...


I did. Thanks again. You seem to have a frighteningly clear grasp of what I'm trying to do. :-)


fb
--
"I've been on the wagon now for more than a decade. Not a single goto
 in all that time. I just don't need them any more. I don't even use
 break or continue now, except on social occasions of course. And I
 don't get carried away." --Richard Heathfield (in comp.lang.c)
.



Relevant Pages

  • Re: is this possible
    ... >> i created an object of type BankAccount which has a constructor ... >> BankAccount(String str,int accountnumber) ... >> now, somewhere in my program, i need a method in the BankAccount class ...
    (comp.lang.java.help)
  • Re: is this possible
    ... > i created an object of type BankAccount which has a constructor ... > BankAccount(String str,int accountnumber) ... > now, somewhere in my program, i need a method in the BankAccount class ...
    (comp.lang.java.help)
  • Re: Passing NULL Objects
    ... > public BankAccount searchAccounts (VectorbankAccounts, ... > long accountNumber){ ... > Vector to the calling function ...
    (comp.lang.java.help)
  • illegal start of expression?
    ... I'm trying to pass in an object of type BankAccount in this method. ... public class BankAccount{//Data attributes long accountNumber; String accountType; ... public void addCredit ...
    (comp.lang.java.help)
  • Re: Passing NULL Objects
    ... public BankAccount searchAccounts (VectorbankAccounts, long accountNumber){int accNum=0; ... //I want to return the object that matches from the Vector to the calling function else return ?? ...
    (comp.lang.java.help)