Home » Core Java » apache » commons » Page 5

commons

Array reverse order

With this example we are going to demonstrate how to reverse the order of an array. We are using the org.apache.commons.lang3.ArrayUtils class, that provides operations on arrays, primitive arrays (like int[]) and primitive wrapper arrays (like Integer[]). In short, to reverse the order of an array you should: Create a String array. Use the toString(Object array) method of ArrayUtils to get ...

Read More »

Array of Objects to Array of primitives

This is an example of how to convert an array of Objects to an array of primitives. We are using the org.apache.commons.lang3.ArrayUtils class, that provides operations on arrays, primitive arrays (like int[]) and primitive wrapper arrays (like Integer[]). Converting an array of Objects to an array of primitives implies that you should: Create an array of Integer objects. Convert the objects ...

Read More »

Check empty string

In this example we shall show you how to check if a String is empty. We are using the org.apache.commons.lang3.StringUtils class, that provides operations on String that are null safe.. To check if a String is empty one should perform the following steps: Create a few String objects. Use the isBlank(String s) method to check if a String contains text. Use the ...

Read More »

Find elements in an array

With this example we are going to demonstrate how to find elements in an array. We are using the org.apache.commons.lang3.ArrayUtils class, that provides operations on arrays, primitive arrays (like int[]) and primitive wrapper arrays (like Integer[]). In short, to find elements in an array you should: Create a String array. Use contains(Object[] array, Object objectToFind) method of ArrayUtils to check if ...

Read More »

Decode Base64

This is an example of how to decode Strings with the Base64 algorithm. We are using the org.apache.commons.codec.binary.Base64 class that provides Base64 encoding and decoding as defined by RFC 2045. Decoding with org.apache.commons.codec.binary.Base64 class implies that you should: Create a String. Get the bytes from the String, using getBytes() API method of String. Use decodeBase64(byte[] base64Data) API method, using the byte ...

Read More »

Encode Base64

In this example we shall show you how to encode Strings with the Base64 algorithm. We are using the org.apache.commons.codec.binary.Base64 class that provides Base64 encoding and decoding as defined by RFC 2045. To encode a String with Base64 one should perform the following steps: Create a String. Get the bytes from the String, using getBytes() API method of String. Use encodeBase64(byte[] ...

Read More »

Move Directory

With this example we are going to demonstrate how to move a Directory. We are using the org.apache.commons.io.FileUtils class that provides general file manipulation utilities. In short, to move a Directory you should: Create a new File instance by converting a given pathname string that is the source into an abstract pathname. Create a new File instance by converting a given ...

Read More »

Get Disk Free Space

This is an example of how to get the Disk free space in Java. We are using the org.apache.commons.io.FileSystemUtils class that provides static utility methods for general file system functions not provided via the JDK File class. Getting the free space of a Disk implies that you should: Use freeSpaceKb(String path) that returns the free space on a drive or volume ...

Read More »

Get directory size

In this example we shall show you how to get the size of a directory. We are using the org.apache.commons.io.FileUtils class that provides general file manipulation utilities. To get the size of a directory one should perform the following steps: Create a String with the path to the directory. Create a new File instance by converting the given pathname string into an ...

Read More »

Create a copy of a file

With this example we are going to demonstrate how to create a copy of a file. We will make use of the org.apache.commons.io.FileUtils class, that provides file manipulation utilities. In short, to create a copy of a file you should: Create a new File by converting the given pathname string of the initial file into an abstract pathname. Create a ...

Read More »