小编Ann*_*a89的帖子

如何从方法中返回不同数据类型的多个值?

我有以下方法,

public Response process(Applicant appl)
{

    String responseString;
    String requestString;
    requestString = createRequestString(appl);
    responseString = sendRequest(requestString);
    Response response = parseResponse(responseString);
    return response;
}
Run Code Online (Sandbox Code Playgroud)

在这里,我想返回responseString和response,一个是String类型,另一个是Response类的对象.我怎样才能做到这一点?

java

3
推荐指数
1
解决办法
3万
查看次数

将String设置为不为null的值

我有2个字符串变量autoCollateralsecureCollateral.我需要将值设置为collateral具有非null值的变量的值.

我把代码编写为

if(autoCollateral!=null){
  collateral=autoCollateral
} 
if(secureCollateral!=null){
  collateral=secureCollateral
}.
Run Code Online (Sandbox Code Playgroud)

如果两者都有价值,我需要设置它们中的任何一个......最优化的方法是什么?

java

0
推荐指数
1
解决办法
746
查看次数

我如何从1开始而不是从零开始索引数组?

for (int i = 0; i < reports.length; i++) {

  Products[] products = reports[i].getDecisions;

  for (int j = 0; j < products.length; j++) {

  }
}
Run Code Online (Sandbox Code Playgroud)

在这里,我想从1开始索引内部for循环,但它没有按预期工作,我也改变了j

java

-1
推荐指数
2
解决办法
2万
查看次数

标签 统计

java ×3