CORE API / CATATAN</>↗Core API07 Jan 2017
You want to convert numbers into their Roman numerals representation and vice versa. The solution here is to tackle the problem as a unary problem where the Roman numerals represented as a single element, the “I” character. We start by representing the number as a repeated sequence of the “I” characters. And then replace the […]
APACHE HTTPCOMPONENTS / CATATAN</>↗Apache HttpComponents06 Jan 2017
The following code snippet show you how to send POST request with a JSON body using HttpClient. The payload in this example is a user information containing id, first_name and a last_name. We placed the payload in an object called StringEntity and also set its content type to ContentType.APPLICATION_FORM_URLENCODED. On the other end called by […]
CORE API / CATATAN</>↗Core API05 Jan 2017
The following code snippet will teach you how to align string in left, right or center alignment when you want to print out string to a console. We will print the string using the printf(String format, Object… args) method. The format specifier / parameter defines how the string will be formatted for output and the […]
APACHE COMMONS / CATATAN</>↗Apache Commons02 Jan 2017
To sort file names by their extension, we can use the ExtensionFileComparator class from the Apache Commons IO library. This class provides a couple instances of comparator such as: Comparator Description EXTENSION_COMPARATOR Case sensitive extension comparator EXTENSION_REVERSE Reverse case sensitive extension comparator EXTENSION_INSENSITIVE_COMPARATOR Case insensitive extension comparator EXTENSION_INSENSITIVE_REVERSE Reverse case insensitive extension comparator EXTENSION...
APACHE COMMONS / CATATAN</>↗Apache Commons02 Jan 2017
In this example, you will learn how to sort files and directories based on their size. Using the Apache Commons IO, we can utilize the SizeFileComparator class. This class provides some instances to sort file size such as: Comparator Description SIZE_COMPARATOR Size comparator instance – directories are treated as zero size SIZE_REVERSE Reverse size comparator […]
APACHE COMMONS / CATATAN</>↗Apache Commons01 Jan 2017
The following example show how to use the Apache Commons IO library to read a text file line by line to a List of String. In the code snippet below we will read the contents of a file called sample.txt using FileUtils class. We use FileUtils.readLines() method to read the contents line by line and […]