Home » Core Java » util » Page 6

util

java.util.concurrent.CopyOnWriteArrayList Example

In this post, we are going to discuss about the class java.util.concurrent.CopyOnWriteArrayList and give you and idea of how you can use it on your own code when building robust multi-threaded applications. 1. Introduction Data structures are a basic element in programming. Almost every program uses one or more types of data structures to store and manage their data. Java ...

Read More »

Java RunnableFuture Example

In this post, we are going to discuss about the class java.util.concurrent.RunnableFuture and give you and idea of how you can use it on your own code when building robust multi-threaded applications. 1. RunnableFuture Class Usually, when you develop a simple, concurrent-programming application in Java, you create some Runnable objects and then create the corresponding Thread objects to execute them. ...

Read More »

java.util.Deque – Deque Java Example

In this example, we are going to explain the java.util.Deque Deque Java interface. The interface name is an abbreviation of “Double Ended Queue”, and it is essentially a queue that implements methods which allows the developer to add elements to both ends of the queue (head and tail). We are going to show the most important methods of this interface, ...

Read More »

java.util.regex.PatternSyntaxException Example

In this example we will discuss about java.util.regex.PatternSyntaxException. This exception is thrown when a regex (a regular exception) pattern is not correct, i.e. has syntax errors. The PatternSyntaxException extends IllegalArgumentException, which means that an argument passed to a method is illegal or inappropriate. Just like IllegalArgumentException, PatternSyntaxException is a runtime exception (indirect subclass of RuntimeException). This means that the try-catch ...

Read More »

Java Currency Example – Working with money

In this example we will discuss about Currency class and its usage. This class represents a currency based on the ISO 4217 currency codes. The class is designed so that there’s never more than one Currency instance for any given currency. Therefore, there’s no public constructor. You obtain a Currency instance using the getInstance() methods. Currency extends the Object class, ...

Read More »

Java Unzip File Example

Java provides us java.util.zip package which contains suitable classes for compressing/decompressing data from Zip and Gzip file formats. You can have a look at this package and all the utility classes that includes, at the documentation of java.util.zip package. In our example we are going to show you how to decompress a zip file and put all the included files ...

Read More »

java.util.MissingResourceException – How to resolve Missing Resource Exception

In this example we will discuss about MissingResourceException. This exception is a runtime exception, and it’s thrown when a resource is missing. MissingResourceException extends RuntimeException which is the base class of all exceptions that can be thrown during the normal operation of Java Virtual Machine. By extending RuntimeException, we don’t have to catch MissingResourceException in the code, neither to declare ...

Read More »

Java ResourceBundle Example

In this post, we are going to discuss about the class java.util.ResourceBundle 1. ResourceBundle Class Resource bundles contain locale-specific objects. When your program needs a locale-specific resource, a String for example, your program can load it from the resource bundle that is appropriate for the current user’s locale. In this way, you can write program code that is largely independent ...

Read More »

Java List Remove Object Example

In this example we will discuss how to remove objects from a java.util.List. There are 2 methods described in the Java API to do so : E remove(int index) We can use index of list to remove the object. boolean remove(Object o)   We can pass the object itself which needs to be removed. For this method to work for ...

Read More »

Java List to Array Example

In this example, we will see how to convert a List (java.util.List) in Java into an array. java.util.List has two methods to do so : T[] toArray(T[] a) – returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified ...

Read More »