Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Add an element to ArrayList using addall() method

import java.util.ArrayList;
import java.util.HashSet;

class Main {
  public static void main(String[] args) {

    // create a set
    HashSet<String> vowels = new HashSet<>();
    vowels.add("a");
    vowels.add("e");
    vowels.add("i");
    vowels.add("o");
    vowels.add("u");

    // create an arraylist
    ArrayList<String> alphabets = new ArrayList<>();

    // add all elements of set to arraylist
    alphabets.addAll(vowels);
    System.out.println("ArrayList: " + alphabets);
  }
}
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Add #element #ArrayList #method
ADD COMMENT
Topic
Name
5+3 =