Sort arraylist and collection in java (Comparable and Comparator)

This tutorial shows the use java.lang.Comparable and java.util.Comparator to sort arraylist and collection in java. The arraylist or collection may contain primitive data, string or user defined object. Here is is a good subject for any java programmer. Because if you know and understand how to sort arraylist and collection in Java(Comparable and Comparator) you … Read more

Create instance using class name in Java

You can create instance using class name if Java knows about the class (the class is stored somewhere of the classpath, ie) within the application context. Thus, you can get a reference to this Class and instantiate an its object via the Class class. This technique is applied in many frameworks, web container, for example … Read more

Java filefilter example to list files and directories in a directory

The Java filefilter example shows you how to filter directory using java FileFilter. I create a directoryFilter object that implements the FileFilter interface, then I implement the accept method. The method returns true if the passed parameter is a directory and false if it is not a directory. More information, you saw how we could … Read more

Convert Java collections into JSON and JSON to collections

This sample show you how to convert Java collections into JSON string. A collections of fruit is built and converted to json object. Then whereas json object is convert to collections object

This is output of program jsonFruitNames = [“Banana”,”Apple”,”Orange”,”Kiwi”] jsonFruits = [{“name”:”Banana”,”location”:”Cuba”,”recommend”:”Should buy”},{“name”:”Apple”,”location”:”USA”,”recommend”:”Should eat”},{“name”:”Orange”,”location”:”Holland”,”recommend”:””},{“name”:”Kiwi”,”location”:”Sweeden”,”recommend”:””}] fruit.getName() = Banana fruit.getLocation() = Cuba fruit.getRecommend() = Should … Read more

Java FileNameFilter example to list files with specific extension

If you need to pick up specific extensions from the given directory and you ask yourself how to filter files using Java. Should implement java FilenameFilter class and override accept() method. Then pass object to list() method to get specific file extensions. Java FileNameFilter example will show you all these stuffs.

Run the java … Read more

Please share it if you found this useful
Hide Buttons