This post explains two ways through which we can convert a collection to an array. The collection can be a list or set. First approach is simply calling “toArray” on collection instance. This method returns an Object array, When converting to array it doesn’t consider the data type of the entries in the collection. Below…… Continue reading Different ways to convert collection to an array
Month: August 2017
Different ways to convert list to array
This post explains two ways through which we can convert a list to array. First approach is simply calling toArrayList on list instance. This method returns an Object array, When converting to array it doesn’t consider the data type of the entries in the list. Below is the code snippet list.toArray(); The second approach involves…… Continue reading Different ways to convert list to array
Creating a custom log message format
This post explains how to create a custom log message format. Out of the box java provides two log formats SimpleFormatter and XMLFormatter. Both extends the abstract super class Formatter. We can create our own custom format. Below is the code of the custom format CustomFormatter 1 package Logging; 2 3 import java.util.logging.Formatter; 4 import…… Continue reading Creating a custom log message format
Stubbing final methods
This post explains how to stub a final method. The class to be tested is as shown below Class1 package package5; public class Class1 { public final int method1(int value) { return value * value; } } The test class is as shown below Test Class 1 package package5; 2 3 import org.junit.Before; 4 import…… Continue reading Stubbing final methods