How-to articles, tricks, and solutions about JAVA

How to configure port for a Spring Boot application

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.

How to connect to Oracle using Service Name instead of SID

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:

How to convert a byte array to a hex string in Java?

To convert a byte array to a hexadecimal string in Java, you can use the following method:

How to convert a char array back to a string?

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.

How to convert a char to a String?

To convert a char to a String in Java, you can use the Character.toString method or the String.valueOf method.

How to convert a Collection to List?

In Java, you can convert a Collection (such as Set, Queue, etc.) to a List using the following methods:

How to convert a Java 8 Stream to an Array?

To convert a Java 8 Stream to an array, you can use the toArray() method of the Stream interface.

How to convert an Array to a Set in Java

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.

How to convert an ArrayList containing Integers to primitive int array?

To convert an ArrayList containing Integer objects to a primitive int array in Java, you can use the toArray method and a casting operation.

How to convert an int array to String with toString method in Java

To convert an int array to a string in Java, you can use the Arrays.toString() method from the java.util package.

How to convert array to list in Java

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:

How to convert ASCII code (0-255) to its corresponding character?

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.

How to convert comma-separated String to List?

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.

How to convert float to int with Java

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.

How to convert hashmap to JSON object in Java

To convert a hashmap to a JSON object in Java, you can use the org.json library. Here's an example:

How to convert int[] into List<Integer> in Java?

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.

How to convert Java String into byte[]?

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.

how to convert java string to Date object

To convert a string to a Date object in Java, you can use the parse() method of the SimpleDateFormat class.

How to convert java.util.Date to java.sql.Date?

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.

How to convert jsonString to JSONObject in Java

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:

How to convert List to Map?

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:

How to convert Milliseconds to "X mins, x seconds" in Java?

To convert milliseconds to "X mins, X seconds" in Java, you can use the TimeUnit class from the java.util.concurrent package.

How to convert object array to string array in Java

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.

How to convert String object to Boolean Object?

To convert a String object to a Boolean object in Java, you can use the Boolean.valueOf method:

How to convert String to long in Java?

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.