How to Convert List to Array in Java
Any List can be converted into array of objects by using its toArray method. A string representation of that array can be generated using Arrays.deepToString method. Output:
Any List can be converted into array of objects by using its toArray method. A string representation of that array can be generated using Arrays.deepToString method. Output:
NumberFormat class from java.text package can be used to format numbers. This class provides setMaximumFractionDigits method which can be used to round to 2 decimal places. Output:
To convert a string to date, Java 8 provides DateTimeFormatter.ofPattern method in its java.time package. Output:
If you are working on Java 8, it is recommended to use java.time package. If you are using prior to Java 8, it is often recommended to go for Joda API. In this post, we will discuss on how to get current date and current time using java.time package. To obtain current date from system … Read more
String(char[]) String class accepts char array in its constructor and converts it into string. Output String.valueOf(char[]) String class provides valueOf method which accepts char array and returns a String object. StringBuilder.append(char[]) StringBuilder class provides an append method that can accept a char array. This method reads all characters and appends them to the buffer. We … Read more