Home » Core Java » apache » Page 6

apache

Capitalize words of a string

This is an example of how to capitalize the words of a String. We are using the org.apache.commons.lang3.text.WordUtils Class, that provides operations on Strings that contain words. The Class tries to handle null input gracefully. An exception will not be thrown for a null input. Trying to capitalize the words of a String implies that you should: Use capitalize(String str) API ...

Read More »

Generate random alphanumeric string

In this example we shall show you how to generate random alphanumeric String objects. We are using the org.apache.commons.lang3.RandomStringUtils class, that offers operations for random Strings. To generate random alphanumeric String objects one should perform the following steps: Use random(int count, boolean letters, boolean numbers) method to create a random string whose length is the number of characters specified. Use randomAlphabetic(int count) ...

Read More »

Date and Time format

With this example we are going to demonstrate how to make Date and Time formatting. We are using the org.apache.commons.lang3.time.DateFormatUtils class, that provides Date and time formatting utilities and constants. It uses the org.apache.commons.lang3.time.FastDateFormat class, that is a fast and thread-safe version of SimpleDateFormat. In short, to format Date and Time you should: Create a new Date object. Use ISO_DATETIME_FORMAT field ...

Read More »

Word counter

This is an example of how to count the words of a String paragraph, using the org.apache.commons.lang3.StringUtils class. This class provides operations on String that are null safe. Counting the words of a paragraph implies that you should: Create a String that is a paragraph. Create a String word that is the word to search in the paragraph. Use the countMatches ...

Read More »

Convert array to Map

In this example we shall show you how to convert an array to a Map. 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[]). This class tries to handle null input gracefully. An exception will not be thrown for a null array input. To convert an array to a ...

Read More »

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 »