123ArticleOnline Logo
Welcome to 123ArticleOnline.com!
ALL >> Education >> View Article

Java Collection Framework

Profile Picture
By Author: START YOUR CAREER WITH JAVA COURSE THAT GETS YOU A
Total Articles: 520
Comment this article
Facebook ShareTwitter ShareGoogle+ ShareTwitter Share

Collection API is present in java.util package. Collection’s subclasses are used to manage the group of elements without key and value pair. I -Interface c--class Methods of Collection interface public boolean add(Object ob): This method is used to add an object to collection object and List object. This method returns true when we add elements for Collection and List object because they allow duplicate elements.
This method returns false when we add elements for Set and SortedSet object if the new element is duplicate element.
java/j2ee classes bangalore

Set and SortedSet object does not allow duplicates. public boolean addAll(Collection c): This method is used to add all the elements of specified collection object at the end of current collection because insertion order is preserved in case of collection and List. This method returns true when we add elements for Collection and List object because they allow duplicate elements.
This method returns false when we add elements for Set and SortedSet object if the new element is duplicate element.Set and SortedSet object does not allow duplicates.
public int size(): This methods returns the number of elements present in Collection object. public boolean isEmpty(): This method checks whether collection is empty or not. It returns true when Collection object is empty otherwise return false.
public boolean contains(object ob): This method checks whether given object is present in collection or not. public boolean containsAll(Collection c): This method checks whether current collection contains all the elements of specified collection. ppublic boolean remove(Object ob): This method is used to remove first existence of specified object from collection.
public boolean removeAll(Collection c): This method is used to remove similar elements of specified collection from current collection. public boolean retainAll(Collection c): This method is used to remove dissimilar elements of specified collection from current collection. public boolean clear(): This method is used to clear all the elements from collection. public object[] toArray(): This method is used to convert collection objects into array elements.
public boolean equals(Object obj): This method is used to compare two collection objects. public Iterator iterator(): This method returns Iterator object that points before the first record. Iterator interface: Iterator interface provides the facility for traversing the collection objects in forward direction. Iterator interface has three methods.
public boolean hasNext(): This method is used to check whether next element is available or not in the collection object. If next element present in the collection object then it returns true otherwise it returns false. public Object next(): This method is used to retrieve the next element in the collection object. public void remove(): This method is used to remove the current element from collection object. List List interface is available in java.util package and extends Collection interface. Best core java training in Bangalore

It provides the following functionalities to sub classes. The elements are stored based on index. We can access any element directly based on specified index. List subclasses allows duplicates and null values. Reverse direction traversing is possible. We can insert elements either at the end of List object or at specific index. Commonly used methods of List interface: public object get(int index): This method is used to get element from the specified index. public object set(int index, Object element): This method is used to replace the existing element from List with given element from specified index.
public void add(int index,Object element): This method is used to insert the element at specified index. public void addAll(int index,Collection c): This method is used to insert the elements of specified collection object to current object at specified index. public void remove(int index): This method is used to remove the element at specified index. public int indexOf(Object element): This method is used to return the first occurrence of specified element.
public int lastIndexOf(Object element): This method is used to return the last occurrence of specified element. public ListIterator listIterator(): This method is used for accessing the data from List object either in forward or in backward. public ListIterator listIterator(int index): This method is used for accessing the data from List object that points to specified index.
ListIterator interface: ListIterator interface provides the facility for traversing the List objects either in forward or in backward direction. ListIterator interface has following methods public boolean hasNext(): This method is used to check whether next element is available or not in the List object. If next element present in the List then it returns true otherwise it returns false. public Object next(): This method is used to retrieve the next element in the collection object.
public boolean hasPrevious(): This method is used to check whether previous element is available or not in the List object. If previous element present in the List then it returns true otherwise it returns false. public Object previous(): This method is used to retrieve the previous element in the collection object.

More About the Author

We offer innovative and customized Java Training in Bangalore. Best Java course in Bangalore with Certified Experts. Go to free demo classes, get prepared by 8yrs experienced tutors and furthermore get hands on live project. Visit: http://infocampus.co.in/java-training-bangalore.html

Total Views: 158Word Count: 880See All articles From Author

Add Comment

Education Articles

1. Icar Coaching Chandigarh
Author: Arun Sharma

2. Agriculture Coaching In Chandiagrh
Author: Arun Sharma

3. 3d Architectural Interior Design Course, Benefits And Scope
Author: Yait Institute

4. Career Opportunities In The Government Sector After Completing Engineering In India
Author: Aditya Institute of Technology and Management

5. What Changes Are Brought To You After Entering An Engineering College?
Author: SIT Pune

6. Osb Online Training Hyderabad
Author: kranthicynixit

7. 12th Standard Hsc Commerce Books – Not All Are Equal
Author: Reliable Publications

8. Ai Training In Hyderabad
Author: Analytics Path

9. Should High School Students Be Allowed To Bring Cell Phones To School?
Author: Abhinav

10. Schools In Kumbakonam
Author: Codeshoppy

11. Kumbakonam Cbse School List
Author: Codeshoppy

12. Top Countries For Teaching English Abroad
Author: Ashams Vijayan

13. Princeton Course Offerings
Author: Imran Ghani

14. Aws Certified Solutions Architect Associate Certification
Author: Sprintzeal

15. Best Bsc Agriculture Coaching In Chandigarh
Author: Arun Sharma

Login To Account
Login Email:
Password:
Forgot Password?
New User?
Sign Up Newsletter
Email Address: