How-to articles, tricks, and solutions about JAVA
To configure the port for a Spring Boot application, you can use the server.port property in the application's configuration file. The configuration file can be a application.properties file in the classpath, or a application.yml file in the classpath.
To connect to an Oracle database using a service name instead of a SID (System Identifier), you can use the thin driver and specify the connection URL in the following format:
To convert a byte array to a hexadecimal string in Java, you can use the following method:
To convert a char array back to a String in Java, you can use the String class's constructor that takes a char array as an argument.
To convert a char to a String in Java, you can use the Character.toString method or the String.valueOf method.
In Java, you can convert a Collection (such as Set, Queue, etc.) to a List using the following methods:
To convert a Java 8 Stream to an array, you can use the toArray() method of the Stream interface.
To convert an array to a Set in Java, you can use the Arrays.asList() method to create a List from the array, and then use the List.toSet() method to create a Set from the List.
To convert an ArrayList containing Integer objects to a primitive int array in Java, you can use the toArray method and a casting operation.
To convert an int array to a string in Java, you can use the Arrays.toString() method from the java.util package.
To convert an array to a list in Java, you can use the Arrays.asList() method. This method returns a fixed-size list backed by the specified array. Here's an example:
To convert an ASCII code (0-255) to its corresponding character in Java, you can use the char data type and cast the ASCII code to it.
To convert a comma-separated String to a List in Java, you can use the String.split() method to split the string into an array of substrings, and then use the Arrays.asList() method to create a list from that array.
To convert a float to an int in Java, you can use the (int) type cast operator. The (int) operator will truncate the decimal part of the float value and convert it to an int.
To convert a hashmap to a JSON object in Java, you can use the org.json library. Here's an example:
To convert an int[] array into a List<Integer> in Java, you can use the Arrays.stream() method to create a stream of the array, and then use the mapToObj() method to map each element of the stream to an Integer object.
To convert a Java string into a byte array, you can use the getBytes() method of the java.lang.String class. This method returns an array of bytes representing the string in a specific encoding.
To convert a string to a Date object in Java, you can use the parse() method of the SimpleDateFormat class.
To convert a java.util.Date object to a java.sql.Date object in Java, you can use the java.sql.Date constructor that takes a long value as an argument.
To convert a JSON string to a JSONObject in Java, you can use the JSONObject constructor that takes a String as an argument, like this:
To convert a List to a Map in Java, you can use the stream() method and the collect() method along with a Collectors.toMap() call. Here's an example of how to do this:
To convert milliseconds to "X mins, X seconds" in Java, you can use the TimeUnit class from the java.util.concurrent package.
To convert an object array to a string array in Java, you can use the toString() method of the Object class and the map() method of the Stream class.
To convert a String object to a Boolean object in Java, you can use the Boolean.valueOf method:
To convert a string to a long in Java, you can use the parseLong() method of the java.lang.Long class. This method parses the string as a signed decimal long, and returns the resulting long value.