ArrayList

In this tutorial, I am going to share with you a few different techniques you can use to iterate over a collection in Java. Iterating ArrayList with Enhanced For-Loop List<String> names = new ArrayList<>(); names.add(“Sergey”); names.add(“Bill”); names.add(“John”); for(String name: names) { System.out.println(name); } Output: Sergey Bill John We declare a List of String objects named…

Read More Iterating over Collections in Java: Examples

In this short code example I am going to share with you how to concatenate two ArrayList in Java.  Concatenate ArrayList using addAll() function Let’s say we have these two ArrayList(s): List<String> itemsList1 = new ArrayList(Arrays.asList(“One”, “Two”)); List<String> itemsList2 = new ArrayList(Arrays.asList(“Three”, “Four”)); To concatenate the two lists together we can create a new ArrayList, and…

Read More Concatenate Two ArrayList in Java