Java Sample App

To help you get started, we have provided Java code snippet below. This snippet shows how to make queries and fetch entries from Contentstack.

class App {
   public static void main(String[] args) {
       try {
           final Stack stack = Contentstack.stack("blt7979d15c28261b93", "cs17465ae5683299db9d259cb6", "production");
           ContentType contentType = stack.contentType("news");
           Query query = contentType.query();
           query.find(new QueryResultsCallBack() {
            @Override
           public void onCompletion(ResponseType responseType, QueryResult queryresult, Error error) {
                   if (error == null) {
                       List<Entry> result = queryresult.getResultObjects();
                       for (Entry entry : result){
                           System.out.println("Title: " + entry.toJSON().getString("title"));
                       }
                   }
               }
           });
 
       } catch (Exception e) {
           System.out.println(e.getMessage());
       }
   }
}

Result:

Title: Modi in Nepal LIVE UPDATES: PM arrives in temple town Janakpur, will ‘rebuild’ on gains from K P Oli’s India visit
Title: IPL 2018, DD vs SRH: Rishabh Pant’s heroics could not save Delhi Daredevils against Sunrisers Hyderabad

On This Page

top-arrow