How to search for a string in an arraylist

List <String> list = new ArrayList(); list.add(“behold”); list.add(“bend”); list.add(“bet”); list.add(“bear”); list.add(“beat”); list.add(“become”); list.add(“begin”); List <String> listClone = new ArrayList<String>(); for (String string : list) { if(string.matches(“(?i)(bea).*”)){ listClone.add(string); } } System.out.println(listClone);

Why is an ArrayList of ArrayLists not multidimensional?

Cay S. Horstmann has stated within his book Core Java for the impatient: There are no two-dimensional array lists in Java, but you can declare a variable of type ArrayList<ArrayList<Integer>> and build up the rows yourself. due to the fact that ArrayLists can expand and shrink and become jagged rather than multi-dimensional, one could say … Read more

Memory overhead of Java HashMap compared to ArrayList

If you’re comparing HashMap with ArrayList, I presume you’re doing some sort of searching/indexing of the ArrayList, such as binary search or custom hash table…? Because a .get(key) thru 6 million entries would be infeasible using a linear search. Using that assumption, I’ve done some empirical tests and come up with the conclusion that “You … Read more

How to iterate an ArrayList inside a HashMap using JSTL?

You can use JSTL <c:forEach> tag to iterate over arrays, collections and maps. In case of arrays and collections, every iteration the var will give you just the currently iterated item right away. <%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core” %> <c:forEach items=”${collectionOrArray}” var=”item”> Item = ${item}<br> </c:forEach> In case of maps, every iteration the var will give … Read more