How-to articles, tricks, and solutions about JAVA
To get the key for a given value in a java.util.HashMap, you can use the entrySet() method of the java.util.HashMap class to get a set of the mappings in the map, and then iterate over the set and check the value of each mapping.
To perform HTTPS client certificate authentication in Java, you can use the HttpsURLConnection class and the SSLSocketFactory class.
To initialize an int array in a constructor in Java, you can use an initializer list as follows:
In Java, an inner class is a class that is defined within another class. An inner class has access to the members (fields and methods) of the outer class, and can be used to encapsulate the implementation of a component of the outer class.
In Java, there are several ways to convert an int value to a String:
To check if a Java List contains an object with a specific field value, you can use the List.stream().anyMatch() method along with a lambda expression to filter the elements in the list based on the field value.
To pass a method as a parameter in Java, you can use a functional interface and a lambda expression.
To implement a recursive Fibonacci sequence in Java, you can define a recursive method that returns the nth number in the sequence.
To check if a ResultSet object contains any results in Java, you can use the next method of the ResultSet class.
If you receive the error "Illegal key size or default parameters" in Java, it means that you are trying to use a cryptographic algorithm with a key size that is not allowed by the jurisdiction policy files.
In Java, you can use the length field of an array to determine the size of the array. For example, given an array arr, you can get the size of the array using arr.length.
In JavaScript, you can use the following special characters to add a new line in a string:
To split a string in Java using a dot (.) as the delimiter, you can use the split method of the String class.
To convert a string to a date in Java, you can use the parse method of the SimpleDateFormat class.
To URL encode the query string parameters of a URL in Java, you can use the URLEncoder class from the java.net package.
To get the current index/key in a "for each" loop, you can use the for loop instead.
To replace a substring in a string in Java, you can use the replace() method of the String class.
To convert a List<String> to a single string by joining the elements of the list with a separator, you can use the join() method of the java.util.StringJoiner class.
To get the first item from a collection in Java, you can use the iterator() method to get an iterator for the collection, and then call the next() method on the iterator to get the first element.
To get the month integer from a java.util.Date object in Java, you can use the getMonth() method of the java.util.Calendar class.
Here is an example of how you can split an ArrayList into multiple smaller ArrayLists in Java:
To get input from the System.console() in Java, you can use the readLine() method of the Console class.
There are several ways to initialize a String array in Java. Here are a few examples:
To read a text file in Java, you can use the BufferedReader class from the java.io package.
To get the position of a match in a String in Java, you can use the indexOf() method of the String class.