将对象实例分配给数组

时间:2015-05-05 14:49:42

标签: java arrays bufferedreader java-io

我正在使用$infos = array( 'METHOD' => 'DoDirectPayment', 'USER' => $paypal_pros_username, 'PWD' => $paypal_pros_password, 'SIGNATURE' => $paypal_pros_signature, 'VERSION' => urlencode('115'), 'PAYMENTACTION' => $_POST['paypal_pros_transaction_type'], 'IPADDRESS' => $_SERVER['REMOTE_ADDR'], 'CREDITCARDTYPE' => $_POST['creditCardType'], 'ACCT' => $_POST['creditCardNumber'], 'EXPDATE' => $_POST['expDateMonth'].$_POST['expDateYear'], 'CVV2' => $_POST['cvv2Number'], //'EMAIL' => $_POST['email'], 'FIRSTNAME' => $_POST['firstName'], 'LASTNAME' => $_POST['lastName'], 'STREET' => $_POST['address1'], 'CITY' => $_POST['city'], 'STATE' => $_POST['state'], 'ZIP' => $_POST['zip'], 'COUNTRYCODE' => $_POST['country'], 'AMT' => $_POST['amount'], 'CURRENCYCODE' => $_POST['PayPal_pros_curency'], 'DESC' => $_POST['paypal_pro_desc'], 'NOTIFYURL' => 'https://website.com/ipn.php' ); // Loop through $infos array to generate the NVP string. $nvp_string = ''; foreach($infos as $var=>$val) { $nvp_string .= '&'.$var.'='.urlencode($val); } // Send NVP string to PayPal and store response // Set the curl parameters. $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $strPurchaseURL); curl_setopt($ch, CURLOPT_VERBOSE, 1); // Turn off the server and peer verification (TrustManager Concept). curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POST, 1); // Set the request as a POST FIELD for curl. curl_setopt($ch, CURLOPT_POSTFIELDS, $nvp_string); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); // Get response from the server. $result = curl_exec($ch); // Parse the API response parse_str($result, $output); if(array_key_exists('ACK', $output)){ print_r($output); if($output['ACK']=="Success"){ //Success email } elseif($output['ACK']=="Failure"){ } else { echo 'There is any error! Please go back and try again.'; } } else { echo 'There is any error! Please go back and try again.'; } bufferedFileReader来读取lineScanner文件,以逗号分隔并将该行中的第一个标记分配给类csv的对象。此后的每个标记都分配给Team

变量

我有这部分工作正常。接下来的部分是将这些对象放入一个数组,我不知道该怎么做。我假设我需要在while循环的底部放置一些代码(可能是for循环),但我不确定。

该课程的代码是:

Team

2 个答案:

答案 0 :(得分:2)

将此添加到您的属性中:

private List<Team> myTeam=new ArrayList<Team>();

然后在你的循环中添加这一行:

myTeam.add(aTeam);

如果绝对必须是array而不是ArrayList,那么请在循环后执行此操作:

Team[] myArray=new Team[myTeam.size()];
myTeam.toArray(myArray);

答案 1 :(得分:0)

public class Pool
{  
    private int teamCounter;
    ...

    public Pool(String aName)
    {
        super();
        this.poolName = aName;
        this.teams = new Team[NOOFTEAMS];
        teamCounter=0;
    }

    ...

    public void loadTeams()
    {
        ...
        //somewhere here I need to add the aTeam object to the array
        this.teams[teamCounter++]=aTeam;

    }
}
相关问题