killerbng icon

working test

killerbng | PRO | 09/16/16 12:58:08 AM UTC | 0 ⭐ | 310 👁️ | Never ⏰ | []
Java |

1.05 KB

|

None

|

0 👍

/

0 👎

package arraylisttesting;
import java.util.ArrayList;
import java.util.Arrays;
 
public class DoesItemExist {
    
    public static ArrayList<ArrayList<String>> temp = new ArrayList<ArrayList<String>>();
    
    public static boolean checkExist(String num){
        for(ArrayList<String> a : temp){
            if(a.get(0).equals(num)){
                return true;
            }
        }
        return false;
    }
    
    public static void main(String[] args) {
        ArrayList<String> al = new ArrayList<>(
            Arrays.asList(
                    "5", "a", "b", "c"
            )
        );        
        temp.add(al);
        ArrayList<String> al2 = new ArrayList<>(
            Arrays.asList(
                    "6", "z", "y", "x"
            )
        );        
        temp.add(al2);
        
        System.out.println(temp);
        System.out.println();
        
        if(checkExist("3")) System.out.println("3 exist.");
        
        if(checkExist("5"))System.out.println("5 exist.");  
    }
    
}

Comments