追加する必要がある4つの文字列があります。Java/Android:複数の文字列を追加し、文字列がヌルの場合はスキップします。
String food = extras.getString("food");
String file = extras.getString("file");
String parcel = extras.getString("parcel");
String others = extras.getString("others");
String itemList = new StringBuilder(food).append("\n")
.append(file).append("\n")
.append(parcel).append("\n")
.append(others).toString();
このコードますprints
、私はFood
とFile
を選択した場合。 Parcel
以来
Food
File
null
null
と他の人は、それは以下のように印刷されるようにする方法、(null
である)値を持ちませんか?
Food
File
if else
を使用しようとしましたが、長すぎます(可能性は14です)。それを短く効果的にする他の方法はありますか?
「エクストラ」の種類 –
@PavneetSinghバンドル – August
サポートしている最小APIレベルは?あなたはこのようなものを使用することができます 'String food = extras.getString(" food "、" ");' –