Parse json string and java object into Gson tree model

GSON Tree Model API provides JsonParser help you parse Json string to tree model of JsonElement. Beside, JsonElement provides method isJsonXXX() and getAsYYY() to check type of Json element and get value of element on that tree node. On the writing, Gson Tree Model API provides method toJsonTree help you converts a java object into … Read more

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

Please share it if you found this useful
Hide Buttons