ArrayList.isEmpty()

ArrayList

ArrayList.isEmpty() Checking if any element is present inside the ArrayList.
It returns boolean value, true if the ArrayList is empty, false otherwise.

Examples with output

add()
ArrayList<String> languages = new ArrayList<String>();
System.out.println(languages.isEmpty()); // true
languages.add("Java");
languages.add("PHP");
languages.add("Python");
System.out.println(languages.isEmpty()); // false
ArrayList<Integer> marks = new ArrayList<Integer>();
System.out.println(marks.isEmpty()); // true
marks.add(55);
marks.add(54);
marks.add(55);
marks.add(54);
System.out.println(marks.isEmpty()); // false
At the second line we have a blank ArrayList ( without any elements inside ) so the isEmpty() returns true. After this we have added elements by using add() , so the last line is returning true as the ArrayList is no longer empty. ArrayList Tutorials


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com



    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer