2017-03-22 23 views
0
ArrayList<Integer> hLProductList = getPointsValue(
        Utility.convertToTextList(mProductListingPage.getProductPoints())); 
      logReport("hLProductList : ===== " + hLProductList); 

List is displaying as hLProductList : ===== [2490, 990, 6870, 1870, 3740, 1240, 7370, 4370, 2870, 3740, 7370, 990, 2240, 3740, 7120, 3110, 1870, 2120, 3120, 8740, 930, 1870, 4370, 1240, 5620, 2620, 6240, 4620, 4990, 1870, 4120, 1240, 7120, 2120, 1870, 6990, 1620, 3110, 1610, 3240, 3870, 3120, 1870, 370, 2490, 3740, 1490, 3120] 

このリストの値を1〜10000の範囲で確認する方法。特定の範囲の整数値を確認する方法

答えて

0

リストの各要素が限界の間で、あなたがJava8を使用していることを確認したい場合は、以下の(ストリーム・アプローチ)を行うことができます。

if(hlProductList.stream().allMatch(x -> x>=1 && x<=10000)){ 
    //all in the range 
} 
else{ 
    //otherwise 
} 

あなたが使用していない場合

boolean oneOutOfRange = false; 
for (Integer i : hlProductList){ 
    if (i>10000||i<1){ 
     oneOutOfRange=true; 
     break; 
    } 
    } 
if (oneOutOfRange){ 
} 
+2

を理由だけではなく 'hlProductList.stream()allMatch(X - > X> = 1 && X <= 10000)'? –

+1

私はjava8を使用していません –

+1

@ OleV.V。ヒントをありがとう、それを修正しました! –

0

あなたはこのような結果のparam範囲と出力対象とconvertToTextListメソッドを書き換えることができます:

public Range{ 
    int start; 
    int end; 
} 
//... 
public Result{ 
    int[] listResult; 
    boolean outRange; 
} 
ループでリスト上で実行し、各要素をチェックしJava8、

私はconvertToTextListメソッドにサイクルがあると想像します。それがnullでない場合は、サイクルのChe occurencyとRangeパラメータを比較できます。

ので、あなたが今の2つの方法があります:。

Result convertToTextList(List list, Range range){ 
    //...do new cycle with compare if range not null 
} 

//old method rewriting... optimezed 
int[] convertToTextList(List list){ 
    return convertToTextList(list, null).listResult; 
} 
関連する問題