How to use an output parameter in Java?

前端 未结 7 1229
天涯浪人
天涯浪人 2020-12-04 15:40

Could someone please give me some sample code that uses an output parameter in function? I\'ve tried to Google it but just found it just in functions. I\'d like to use this

相关标签:
7条回答
  • 2020-12-04 16:10

    Thank you. I use passing in an object as a parameter. My Android code is below

        String oPerson= null;
        if (CheckAddress("5556", oPerson))
        {
            Toast.makeText(this, 
                    "It's Match! " + oPerson,                   
                    Toast.LENGTH_LONG).show();
        }
    
        private boolean CheckAddress(String iAddress, String oPerson)
    {
        Cursor cAddress = mDbHelper.getAllContacts();
        String address = "";        
        if (cAddress.getCount() > 0) {
            cAddress.moveToFirst();
            while (cAddress.isAfterLast() == false) {
                address = cAddress.getString(2).toString();
                oPerson = cAddress.getString(1).toString(); 
                if(iAddress.indexOf(address) != -1)
                {
                    Toast.makeText(this, 
                            "Person : " + oPerson,                  
                            Toast.LENGTH_LONG).show();
                    System.out.println(oPerson);
                    cAddress.close();
                    return true;                    
                }
                else cAddress.moveToNext();
            }
        }
        cAddress.close();
        return false;
    }
    

    The result is

    Person : John

    It's Match! null

    Actually, "It's Match! John"

    Please check my mistake.

    0 讨论(0)
提交回复
热议问题