Home » commons

Tag Archives: commons

org.apache.commons.net.ftp.ftpclient Example

In this example we are going to elaborate the use of the FTPClient class in the package: org.apache.commons.net.ftp, as the package name says, it is a member of the Apache Commons, and deals with the FTP. As like other classes of the Apache Commons This class also provides us with some really helpful methods. The methods of this class as other classes ...

Read More »

Create a simple BasicDataSource object

With this example we are going to demonstrate how to create a simple org.apache.commons.dbcp.BasicDataSource object, that is the basic implementation of javax.sql.DataSource that is configured via JavaBeans properties. In short, to create a simple BasicDataSource object you should: Create a BasicDataSource object and configure the database. Use setDriverClassName(String driverClassName) method to set the jdbc driver class name. Use setUrl(String url) method ...

Read More »

Check if Days and Calendars match

With this example we are going to demonstrate how to check if Days and Calendars match. We are using the org.apache.commons.lang3.time.DateUtils Class, that is a suite of utilities surrounding the use of the Calendar and Date object. DateUtils contains a lot of common methods considering manipulations of Dates or Calendars. In short, to check if Days and Calendars match you should: ...

Read More »

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 »