Multidimensional Arrays lengths in Java

This will give you the length of the array at index i It’s important to note that unlike C or C++, the length of the elements of a two-dimensional array in Java need not be equal. For example, when pathList is instantiated equal to new int[6][], it can hold 6 int [] instances, each of which can be a different length. … Read more

toring and Retrieving ArrayList values from hashmap

Our variable: Map<String, List<Integer>> map = new HashMap<String, List<Integer>>(); To store: map.put(“mango”, new ArrayList<Integer>(Arrays.asList(0, 4, 8, 9, 12))); To add numbers one and one, you can do something like this: String key = “mango”; int number = 42; if (map.get(key) == null) { map.put(key, new ArrayList<Integer>()); } map.get(key).add(number); In Java 8 you can use putIfAbsent to add … Read more

SQL Developer with JDK (64 bit) cannot find JVM

I just wasted one morning trying to get SQL developer to work on my current setup: OS: Windows 8.1 virtual machine running on mac via Parallels. No oracle client or instant client installed No Java installed The reproducible steps are I downloaded SQL Developer for Windows with JDK (all 64-bit) and unzipped it to C:/Program … Read more

Java regex email

FWIW, here is the Java code we use to validate email addresses. The Regexp’s are very similar: public static final Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile(“^[A-Z0-9._%+-][email protected][A-Z0-9.-]+\\.[A-Z]{2,6}$”, Pattern.CASE_INSENSITIVE); public static boolean validate(String emailStr) { Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(emailStr); return matcher.find(); } Works fairly reliably.

Java Swing revalidate() vs repaint()

You need to call repaint() and revalidate(). The former tells Swing that an area of the window is dirty (which is necessary to erase the image of the old children removed by removeAll()); the latter tells the layout manager to recalculate the layout (which is necessary when adding components). This should cause children of the panel to repaint, but may not … Read more