Saturday, November 29, 2014

COLLECTION IN PROGRAMMING

1. What is a COLLECTION?
            A COLLECTION or COLLECTIONS in Indonesian is an object that represents the collection of an object. This set of homogeneous bias, ie a collection of fruit (oranges, bananas, etc.) or heterogeneous, for example, in one collection contains a collection of fruit, a COLLECTION of a collection of cars, and so forth.
        Java provides a framework for the collection process the data set that we can use in our program. several advantages framework are:

  • • Reduce the time and effort devloment. this is because the framework has been provided and used without having to recreate the data structure and make the algorithm.
  • • Improving Performance. This framework is made with the advanced performance so that we can obtain this performance. Too bnayak effort if the reader make his framework over again.
  • • Ease of interoperability. this framework to facilitate its users to integrate into the system makes.

A collection framework is designed with a touch of a capable architecture. Java provides a framework collection contains, among others:

  • Interface. This is an abstract data type of the collection. interface allows a collection to manipulate freely.
  • Implementation. This is a concrete iplementasi collection of interfaces.
  • Algorithm. This is a method for computing such as search, penguruatan on a collection of objects that implement the interface.

2. Recognize and object collection Mengungunakan
In the framework we can find a java object collection in java.utils package. *. in this sub-section, we will use some of the collection object into the sample program. some of these objects are:


Let's discuss this object:

2.1 List
         List object with the model of double link list, where the kit adapat memasukkanapapun object. relationship to the object list class diagram can be seen in figure 1.1.
To use this object, we must declare package
Import java.util. *;
Installing the object list:
Lista list = new ArrayList ();
how to enter data into the object list as follows:
listA.add ("Element 1");
listA.add ("Element 2");
listA.add ("Element 3");
Above we added a string object.
There are two ways to access the data it is to loop and retrieve data. ilustarsi following program code.
programming java
LIST in JAVA
// how 1
String element 1 = (String) listA.get (0);
String element 2 = (String) listA.get (1);
String element 3 = (String) listA.get (2);
// how 2
Iterator iterator = listA.iterator ();
While (iterator.hasNext ()) {
String element = (String) iterator.next ();
}
Save this program code and compile it. if suskse, we will get the results as follows:
list
LIST in JAVA
       If we want to remove the object from the collection, we can make use of the method remove () with the parameter index, we also can erase the data on the list with a specific object, suppose we remove objects from the collection of the index o.
Boolean success = listA.remove ("third element");
System.out.println ("delete element 3, status =" + success);
Object removed = listA.remove ();
System.out.println ("delete data index 0, data =" + removed);
If the kit ajalan the above program, then we will get the result as shown in Figure 1.3.
list
LIST in JAVA


next material about STACK in JAVA
version in Indonesian Collection dalam pemrograman java

1 comment: