1 / 19

Java Collections Framework: Synchronization, Unmodifiable Collections, and Sorting Methods

This lecture covers important concepts in the Java Collections Framework, including the use of synchronized collections to ensure thread safety and the creation of unmodifiable collections that protect data integrity. Methods for sorting, reversing, and shuffling lists are discussed, along with binary search functionality. The lecture also introduces the ITag interface for custom attribute management in collections. With practical examples and applications, this session aims to enhance understanding of collection manipulation in Java.

tanner
Download Presentation

Java Collections Framework: Synchronization, Unmodifiable Collections, and Sorting Methods

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 14 Generic bean renderer & some more information on collections

  2. public static Collection synchronizedCollection(Collection c); public static Set synchronizedSet(Set s); public static List synchronizedList(List list); public static Map synchronizedMap(Map m); public static SortedSet synchronizedSortedSet(SortedSet s); public static SortedMap synchronizedSortedMap(SortedMap m);

  3. Collection c = Collections.synchronizedCollection(myCollection); synchronized(c) { Iterator i = c.iterator(); // Must be in the synchronized block! while (i.hasNext()) foo(i.next()); }

  4. public static Collection unmodifiableCollection(Collection c); public static Set unmodifiableSet(Set s); public static List unmodifiableList(List list); public static Map unmodifiableMap(Map m); public static SortedSet unmodifiableSortedSet(SortedSet s); public static SortedMap unmodifiableSortedMap(SortedMap m);

  5. public static void sort(List list) // All elements must implement Comparable public static void sort(List list, Comparator c) public static int binarySearch(List list, Object key) // All elements must implement Comparable public static int binarySearch(List list, Object key, Comparator c) public static void reverse(List l) public static void shuffle(List list) public static void fill(List list, Object o) // Sets all elements to be given object public static void copy (List dest, List src) public static Object min[max](Collection coll) // All elements must implement Comparable public static Object min[max](Collection coll, Comparator comp)

  6. public interface ITag { public void init( String name ); public String getName(); public Object getAttribute( String name ); public Iterator getAttributes(); public Iterator getAttributeNames(); public Iterator getChildren(); public void addAttribute( String name, Object value ); public Object getObject(); public void build( ITag parent ) throws ParseException; }

  7. <RESOURCE CLASS=edu.nyu.sejava.iskold.eworld.HomogeneousResource> <PROPERTY NAME=Quantity VALUE=25> <PROPERTY NAME=Base VALUE=a> <PROPERTY NAME=Renewable VALUE=true> </RESOURCE>

More Related