This is an example of how to set a filter on a Logger’s Handler. The Filter is used to provide control over what is logged, beyond the control that the levels provide. Each Logger and each Handler can have a filter associated with it. The Logger or Handler will call the isLoggable(LogRecord record) method to check if a given LogRecord ...
Read More »Log method call
In this example we shall show you how to log a method call. We have implemented the LogMethodCall Class, with a simple method to log its messages. The basic steps of the example are described below: The call(String arg1, Object arg2) method of the class takes a String argument and an Object argument and returns a boolean value. The method ...
Read More »Write Log entries to log file
With this example we are going to demonstrate how to write Log entries to a log file. In short, to write Log entries to a log file you should: Create a new FileHandler to write to a specific file. Create a new Logger instance with getLogger(String name) API method of Logger. Add the handler to the Logger, with addHandler(Handler handler) ...
Read More »Swap List elements example
This is an example of how to swap a List’s elements . We are using the swap(List list, int i, int j) method of the Collections Class. Collections provides static methods that operate on or return collections. We are also using the ArrayList as a List implementation, but the same API applies to any type of List implementation classes e.g. ...
Read More »Shuffle List elements example
In this example we shall show you how to shuffle a List’s elements. This is provided by the shuffle(List list) API method of the Collections class. The Collections class provides static methods that operate on or return collections. The ArrayList is used as a List implementation, but the same API applies to any type of List implementation classes e.g. Vector ...
Read More »Reverse order of List example
With this example we are going to demonstrate how to reverse the order of a List. This is provided by the reverse(List list) API method of the Collections class. The ArrayList is used as a List implementation, but the same API applies to any type of List implementation classes e.g. Vector etc. In short, to reverse the order of a ...
Read More »Replace specific element of List example
This is an example of how to replace a specific element of a List. We will use the replaceAll(List list, Object oldVal, Object newVal) API method of the Collections class. The ArrayList is used as a List implementation, but the same API applies to any type of List implementation classes e.g. Vector etc. Replacing a specific element of a List ...
Read More »Replace all elements of List example
In this example we shall show you how to replace all elements of a List. We will use the fill(List list, Object element) API method of the Collections class. Collections provides static methods that operate on or return collections. The ArrayList is used as a List implementation, but the same API applies to any type of List implementation classes e.g. ...
Read More »Binary search List example
With this example we are going to demonstrate how to Binary search a List. We will use the binarySearch(List list, T key) API method of the Collections class. Collections provides static methods that operate on or return collections. The ArrayList is used as a List implementation, but the same API applies to any type of List implementation classes e.g. Vector ...
Read More »Get unmodifiable Collection
This is an example of how to get an unmodifiable Collection. The same API applies to any type of Collection implementation classes e.g. HashSet, TreeSet, LinkedHashSet, LinkedList etc. Nevertheless Java util API provides separate methods for getting immutable Collection views based on the following Collection implementation classes: – static Collection unmodifiableCollection(Collection) – static List unmodifiableList(List) – static Set unmodifiableSet(Set) – ...
Read More »