Learn to read file content into string in java. Examples use Files.readAllBytes, Files.lines and FileReader & BufferedReader to read file content.
Learn to convert byte to String and String to byte in java – with examples. Conversion between byte array and string may be used in many cases including IO operations, generate secure hashes etc.
Quick references to convert string to int values in java. Included code snippets have examples of converting string values to int or Integer in multiple base or radix. Code snippets to convert string to int Output: 1001 1001 1001 513 513 513 4097 4097 4097 Convert String to int with Integer.parseInt() parseInt() method is overloaded […]
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.