Array Set extends AbstractSet : Set « Collections Data Structure « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » Collections Data Structure » SetScreenshots 
Array Set extends AbstractSet
Array Set extends AbstractSet


import java.io.Serializable;
import java.util.*;

public class ArraySet extends AbstractSet
    implements Cloneable, Serializable {

  private ArrayList list;

  public ArraySet() {
    list = new ArrayList();
  }

  public ArraySet(Collection col) {
    list = new ArrayList();

    // No need to check for dups if col is a set
    Iterator itor = col.iterator();
    if (col instanceof Set) {
      while (itor.hasNext()) {
        list.add(itor.next());
      }
    else {
      while(itor.hasNext()) {
        add(itor.next());
      }
    }
  }

  public Iterator iterator() {
    return list.iterator();
  }

  public int size() {
    return list.size();
  }

  public boolean add(Object element) {
    boolean modified;
    if (modified = !list.contains(element)) {
      list.add(element);
    }
    return modified;
  }

  public boolean remove(Object element) {
    return list.remove(element);
  }

  public boolean isEmpty() {
    return list.isEmpty();
  }

  public boolean contains(Object element) {
    return list.contains(element);
  }

  public void clear() {
    list.clear();
  }

  public Object clone() {
    try 
      ArraySet newSet = (ArraySet)super.clone();
      newSet.list = (ArrayList)list.clone();
      return newSet;
    catch (CloneNotSupportedException e) { 
      throw new InternalError();
    }
  }
}


           
       
Related examples in the same category
1. Things you can do with SetsThings you can do with Sets
2. Putting your own type in a SetPutting your own type in a Set
3. Use setUse set
4. Another Set demo
5. Set substractionSet substraction
6. Working with HashSet and TreeSetWorking with HashSet and TreeSet
7. TreeSet DemoTreeSet Demo
8. Show the union and instersection of two sets
9. Demonstrate the Set interface
10. TreeSet Test
11. Sync Test
12. Set Copy
13. Set and TreeSet
14. Tail
15. What you can do with a TreeSetWhat you can do with a TreeSet
ww__w__.___j__a__v__a___2___s___.___c___o___m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.