Add ArrayList to another ArrayList in java

Then you need a ArrayList of ArrayLists: ArrayList<ArrayList<String>> nodes = new ArrayList<ArrayList<String>>(); ArrayList<String> nodeList = new ArrayList<String>(); nodes.add(nodeList); Note that NodeList has been changed to nodeList. In Java Naming Conventions variables start with a lower case. Classes start with an upper case.

How to connect with Java into Active Directory

Here is a simple code that authenticate and make an LDAP search usin JNDI on a W2K3 : class TestAD { static DirContext ldapContext; public static void main (String[] args) throws NamingException { try { System.out.println(“Début du test Active Directory”); Hashtable<String, String> ldapEnv = new Hashtable<String, String>(11); ldapEnv.put(Context.INITIAL_CONTEXT_FACTORY, “com.sun.jndi.ldap.LdapCtxFactory”); //ldapEnv.put(Context.PROVIDER_URL, “ldap://societe.fr:389”); ldapEnv.put(Context.PROVIDER_URL, “ldap://dom.fr:389”); ldapEnv.put(Context.SECURITY_AUTHENTICATION, “simple”); … Read more

Creating a socket server which allows multiple connections via threads and Java

The problem is that currently you’re accepting the connection, but then immediately performing blocking reads on it until it’s closed: // After a few changes… Socket clientSocket = serverSocket.accept(); BufferedReader in = new BufferedReader(new InputStreamReader( clientSocket.getInputStream())); String nextLine; while ((nextLine = in.readLine()) != null) { System.out.println(nextline); } That means the same thread which accepts the … Read more

Elegant way of counting occurrences in a java collection

Now let’s try some Java 8 code: static public Map<String, Integer> toMap(List<String> lst) { return lst.stream() .collect(HashMap<String, Integer>::new, (map, str) -> { if (!map.containsKey(str)) { map.put(str, 1); } else { map.put(str, map.get(str) + 1); } }, HashMap<String, Integer>::putAll); } static public Map<String, Integer> toMap(List<String> lst) { return lst.stream().collect(Collectors.groupingBy(s -> s, Collectors.counting())); } I think this … Read more

NoClassDefFoundError: org/w3c/dom/ElementTraversal

It looks like ElementTraversal is part of xml-apis-2.10.0.jar which should have been provided with your Shibboleth installation. So if you were following these instructions you should also have followed this step: Endorse Xerces and Xalan by creating the directory JETTY_HOME/lib/endorsed/ and copy the .jar files included in the IdP source endorsed/ directory into the newly … Read more

Why use an abstract class without abstract methods?

To prevent instantiation of that class and use it only as a base class. Child classes can use the general methods defined in the abstract class. For example it doesn’t make sense to create an instance of AbstractVehicle. But All vehicles can reuse a common registerMileage(int) method.