如何在数组中包含这些字符串值。它给我输出loc [j] == 1是简单的loc [j]> 1是扩展的。但我将其存储在字符串中..我需要将这些值存储在字符串数组中。我该怎么做
String s = (loc[j]==1 ? "simple" : (loc[j]>1 ? "extended" : null));
这相当于此代码
if(loc[j]==1)
System.out.println("Simple");
else
System.out.println("extended");
答案 0 :(得分:1)
像这样:
String[] results = new String[loc.length]; // Looks like it should be the same length as loc. If not, change it as needed.
// later on, presumably in a for loop or something
results[j] = (loc[j]==1 ? "simple" : (loc[j]>1 ? "extended" : null));
答案 1 :(得分:0)
如果是single
值,则无需使用数组。了解如何使用Java arrays(教程)
String s=null;
if(loc[j]==1) //I presume that loc is an array of int
s="Simple";
else
if(loc[j]>1)
s="extended";