Skip to main content

List Example

The Caché class Contact contains a method, named ListOfContacts, that assembles a list containing the object IDs for all Contact instances in the database. The method returns an object of Caché type %Library.ListOfDatatypes. The Java projection for Contact also contains a ListOfContacts method.

The following Java client method uses the java.util.List interface to manipulate the data returned by ListOfContacts. The method iterates through the list. For each object ID in the list, it opens the corresponding Contact instance and displays the value of its Name and ID properties.

public class BindingExamples {
   public static void displayContacts(Database db) throws CacheException{
      List listOfContacts = (List)(Contact.ListOfContacts(db));
      Iterator iter = listOfContacts.iterator();
         String id = (String) (;
         Contact contact = (Contact)(Contact._open(db, new Id(id)));
         System.out.println ("Name " + contact.getName() + " ID " + id);
FeedbackOpens in a new tab