Learn to read file content into string in java. Examples use Files.readAllBytes, Files.lines and FileReader & BufferedReader to read file content.
Learn to create enum using strings, iterate over all enum constants, getting single enum value and doing reverse lookup to find enum by string value. Create enum of string constants Example of creating enum with strings. This enum contains deployment environments and their respective URLs. Iterate all enum constants To iterate over all enums, use […]
To convert comma separated string to list in java, you can use below methods. Comma-separated String to List Using Regex You can use regular expression “\\s*,\\s*” to match comma into CSV list and then use String.split() method. Output: [how, to, do, in, java] This resulting List is a fixed-size List backed by the array. It […]
You may need custom serialization in java in may cases. For example, you have legacy java classes which you are not willing to modify for any reason. There can be some design constraints as well. Or even simply, the class is expected to be changed in future releases which could break the deserialization of previously […]
Learn to convert XMLGregorianCalendar to Date class or string value. Also learn to apply timezone changes and daylight saving effects as well.
In this example, we will learn to format XMLGregorianCalendar class to string in multiple patterns e.g. ‘MM/dd/yyyy hh:mm a z’. XMLGregorianCalendar to String in Date/TimeStamp Pattern In below code sample, I am creating instance of XMLGregorianCalendar with current Date object. Then I am formatting it to String format in given pattern. Output: 01/27/2017 01:32 PM […]
To iterate list in java is very basic operation, but over the years it’s gone through some significant changes. We will go through all these changes in given examples.
In this java example, we will learn to convert OutputStream to InputStream which you may need when you read data from one source which return an outputstream; and write/pass the data to other target which wants data in inputstream.
In java, java.util.Locale class represents a specific language and region of the world. If a class varies its behavior according to Locale, it is said to be locale-sensitive. Learn more.
Example of java code to unzip and extract files and sub-directories from a compressed zip file using java.util.zip package.