开发者

For-loop not working the way i want it to

I have a extremely minor issue that I can't seem to figure out. I'm trying to extract data based on a type of value from an ArrayList> and place it into another ArrayList. The issue is that the for-loop only runs once, which in this case i need it to traverse the entire array and then place the data into the unSuppressedData arraylist.

Below is the for-loop:

  for (int x = 0; x < suppressedStatus.length; x++) {
    for (int i = 0; i < availData.size(); i++) {
        Hashtable<String,String> checkAvail = availData.get(i);
        String itemStatus = checkAvail.get("loanStatus");
        if (unSuppressedData.contains(checkAvail) == false) {
            if (!(itemStatus.equals(suppressedStatus[x]))) {
                Log.d("Item Status", itemStatus);
                Log.d("Suppressed Status", suppressedStatus[x]);
                unSuppressedData.add(checkAvail);
                //break;
                }
            }
        }
    }

suppressedStatus is a String array

availData is the arraylist i want to extract data from

unSuppressedData is the arraylist i want to place the data in

I believe that it only runs once is due to this lin开发者_StackOverflowe of code:

 if (unSuppressedData.contains(checkAvail) == false) {

But i need to this line to check whether my unSuppressdData has the data, if no then will add the data from availData arraylist into unSuppressedData arraylist.

Could it be that i'm writing this piece of code wrongly? Appreciate any insights shed on this.


A good collection type for this sort of thing is the LinkedHashSet. Because it's a set, each element can only be added once. Being a hash, the contains test is quick. Being 'linked' the resulting set is iterated in insertion order.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜