5 Ways to Remove Null from ArrayList

5 Ways to Remove Null from ArrayList: Removing null from arraylist become some realtime business scenario many times. Removing null from arraylist is actually easy as it can be. We have many ways to remove null from arraylist.   5 Ways to Remove Null From ArrayList: Using collections.singleton Using removeAll with one null value list Using Iterator Using while loop (rarely used)

211 total views, 1 views today

» Read more

Arraylist vs LinkedList Java

ArrayList Vs LinkedList: ArrayList: 1. Search operation is faster, because it maintains the array structure, so get(index) will search and give the value fastly. 2. Less memory consumption because it maintains element and data. Where in linkedlist it maintains two pointer to store the addresses of the neighbour elements. LinkedList: 1. Remove operation is faster. 2. Insertion operation is faster.

161 total views, 1 views today

» Read more

Finding Common values in Arraylist Java Example

Finding Common values in Arraylist: Two arraylists are iterated one inside another for loop and common values are inserted in the common arraylist. Input: List 1 contains: God .Net PHP Java List 2 contains: C Java C++ .Net Expected Values: Common values are :::Java Common values are :::.Net Java Program to Find Common values in Arraylist: import java.util.ArrayList; import java.util.List;

2,248 total views, 11 views today

» Read more

Taking only String values from ArrayList

Scenario: You are given with a arraylist with all datatype values. Eg: Integer and String values. But you want to move only string values to another arraylist. Solution you can think suddenly: ArrayList can be declared to hold only string and using addAll method we can move. Eg: ArrayList arStr = new ArrayList(); arStr.addAll(“given_arrayList”); But the above one does not

145 total views, 3 views today

» Read more

ArrayList Modification Java Example

ArrayList Modification: package in.javadomain; import java.util.ArrayList; import java.util.ListIterator; public class ReverseIteration { public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("Sachin"); list.add("Gambhir"); list.add("Dhoni"); list.add("Sehwag"); list.add("Raina"); list.add("Yuvraj"); ListIterator<String> li = list.listIterator(); System.out.println("ArrayList Values: \n"); for (String val : list) { System.out.println(val); } System.out.println("\nArrayList Values After Modification: \n"); list.set(1, "Dhawan"); list.set(3, "R.Sharma"); for (String val : list) { System.out.println(val);

135 total views, no views today

» Read more

ArrayList Reverse Iteration Example

ArrayList Iteration: package in.javadomain; import java.util.ArrayList; import java.util.ListIterator; public class ReverseIteration { public static void main(String[] args) { ArrayList<String> list = new ArrayList<String>(); list.add("Sachin"); list.add("Gambhir"); list.add("Dhone"); list.add("Sehwag"); list.add("Raina"); list.add("Yuvraj"); ListIterator<String> li = list.listIterator(); System.out.println("ArrayList Iteration: \n"); while (li.hasNext()) { System.out.println(li.next()); } } } Output: ArrayList Iteration: Sachin Gambhir Dhone Sehwag Raina Yuvraj ArrayList Reverse Iteration: package in.javadomain; import java.util.ArrayList; import

130 total views, no views today

» Read more

Converting HashMap to ArrayList in Java Example

Method 1: You can convert HashMap to ArrayList by simply iterating hashmap keys or values and you can add to arraylist. HashMap to ArrayList Java Program: package in.javadomain; import java.util.ArrayList; import java.util.HashMap; public class HashMapTOArrayList { public static void main(String[] args) { HashMap<Integer, String> hashMap = new HashMap<Integer, String>(); hashMap.put(1, "Google"); hashMap.put(2, "Facebook"); hashMap.put(3, "Youtube"); for(Object hashMapValue : hashMap.entrySet()){ System.out.println("Printing

846 total views, 1 views today

» Read more

Converting Array to Arraylist in Java Example

Array to ArrayList: package in.javadomain; import java.util.ArrayList; import java.util.Collections; import java.util.List; public class ArrayTOArrayList { public static void main(String[] args) { String[] languagesArray = { "Tamil", "English", "Hindi", "Telugu" }; List<String> langArrayList = new ArrayList<String>(); Collections.addAll(langArrayList, languagesArray); for (Object value : langArrayList) { System.out.println("Value in ArrayList :::" + value); } } } Output: Value in ArrayList :::Tamil Value in ArrayList

129 total views, no views today

» Read more

ArrayList to Array in Java Example

ArrayList to Array: The below program converts ArrayList to Array. Java Program: package in.javadomain; import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class ArrayListTOArray { public static void main(String[] args) { List<String> mobilesList = new ArrayList<String>(); mobilesList.add("Nokia"); mobilesList.add("Karbonn"); mobilesList.add("Micromax"); mobilesList.add("Samsung"); Object[] listToObj = mobilesList.toArray(); String[] mobilesArray = Arrays.copyOf(listToObj, listToObj.length, String[].class); System.out.println("Value in Array is ::: " + mobilesArray[2]); } } Output:

157 total views, 1 views today

» Read more
1 2