ArrayList.add()

ArrayList.add(element) Insert element to ArrayList.
boolean : It returns true on successful addition of element at end, otherwise returns false.

Examples with output
ArrayList<String> languages = new ArrayList<String>();
languages.add("Java");
languages.add("PHP");
languages.add("Python");
languages.add("HTML");
System.out.println(languages); //[Java, PHP, Python, HTML]
Using if condition to check the status of adding element to ArrayList
ArrayList<String> languages = new ArrayList<String>();
languages.add("Java");
languages.add("PHP");
languages.add("Python");
languages.add("HTML");
if(languages.add("C++")) {
System.out.println("Successfully added  C++");
}else {
System.out.println("Failed to add C++");	
}
System.out.println(languages); //[Java, PHP, Python, HTML,C++]
Output is here
Successfully added  C++
[Java, PHP, Python, HTML, C++]
ArrayList Tutorials addAll()

Java

Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com






    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