Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement