APACHE COMMONS / CATATAN</>↗Apache Commons05 Agt 2006
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 Commons22 Mei 2006
This code snippet show you how to use HashCodeBuilder and EqualsBuilder class from the Apache Commons Lang library to implement the hashCode() and equals() method of an object. To use both of these classes, we just need to create instance of these classes and append the properties that we will use to calculate the hashcode […]
APACHE COMMONS / CATATAN</>↗Apache Commons17 Mei 2006
package org.kodejava.commons.lang; public class ObjectHashCodeDemo { public static void main(String[] args) { Book book1 = new Book(1L, "Spring Boot in Action", "Craig Walls"); Book book2 = new Book(2L, "Docker in Action", "Jeff Nickoloff"); Book book3 = book1; System.out.println("book1.hashCode() = " + book1.hashCode()); System.out.println("book2.hashCode() = " + book2.hashCode()); System.out.println("book3.hashCode() = " + book3.hashCode()); } } package […]
APACHE COMMONS / CATATAN</>↗Apache Commons13 Mei 2006
The following code snippet shows you how to write strings of data into a file using the Apache Commons IO library. We can use the FileUtils.writeStringToFile() method to do it. This method accepts the file object where the data will be stored, the data itself, and the encoding. package org.kodejava.commons.io; import org.apache.commons.io.FileUtils; import java.io.File; import […]
APACHE COMMONS / CATATAN</>↗Apache Commons12 Mei 2006
In this example, we are going to use the Apache Commons IO library to get or calculate the total size of a directory. The FileUtils class provided by the Commons IO can help us to achieve this goal. The first method that we can use is the FileUtils.sizeOfDirectory(), it calculates the size of a directory […]
APACHE COMMONS / CATATAN</>↗Apache Commons10 Mei 2006
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 […]