APACHE COMMONS / CATATAN</>↗Apache Commons20 Okt 2007
package org.kodejava.commons.lang; import org.apache.commons.lang3.StringUtils; public class EmptyStringCheckDemo { public static void main(String[] args) { // Create some variable to hold some empty string, contains only // whitespaces and words. String one = ""; String two = "\t\r\n"; String three = " "; String four = null; String five = "four four two"; // We can […]
APACHE COMMONS / CATATAN</>↗Apache Commons19 Okt 2007
This example demonstrates how to use the DateUtils.round() method to get the nearest hour, minute and second of a date. package org.kodejava.commons.lang; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateUtils; import org.apache.commons.lang3.time.FastDateFormat; import java.util.Calendar; import java.util.Date; public class DateRoundingDemo { public static void main(String[] args) { FastDateFormat formatter = DateFormatUtils.ISO_...
APACHE COMMONS / CATATAN</>↗Apache Commons19 Okt 2007
The DateFormatUtils class help us to format date and time information. This class uses an instance of org.apache.commons.lang3.time.FastDateFormat class to format the date and time information. Compared to Java SimpleDateFormat, the FastDateFormat class is thread safe. If you want to create a custom date format, you can use the FastDateFormat class directly. package org.kodejava.commons.lang; import […]
APACHE COMMONS / CATATAN</>↗Apache Commons14 Okt 2007
This example demonstrates how to find specific items in an array. We will use the org.apache.commons.lang3.ArrayUtils class. This class provides method called contains(Object[] array, Object objectToFind) method to check if an array contains the objectToFind in it. We can also use the indexOf(Object[] array, Object objectToFind) method and the lastIndexOf(Object[] array, Object objectToFind) method to […]
APACHE COMMONS / CATATAN</>↗Apache Commons10 Okt 2007
This example show how we can use the CompareToBuilder class for automatically create an implementation of compareTo(Object o) method. Please remember, when you are implementing this method, you will also need to implement the equals(Object o) method consistently. This will make sure the behavior of your class is consistent in relation to collection sorting processes. […]
APACHE COMMONS / CATATAN</>↗Apache Commons10 Okt 2007
Implementing toString() method sometimes can become a time-consuming process. If you have a class with a few fields, it might be alright. However, when you deal with a lot of fields, it will surely take some time to update this method every time a new field comes and goes. Here comes the ReflectionToStringBuilder class that […]