0% found this document useful (0 votes)
2 views

Java_Assignment_Comparisons

The document outlines key differences between various Java data structures and concepts, including Arrays vs Collections, ArrayList vs LinkedList, List vs Set, Collection vs Collections, and Comparable vs Comparator. Arrays are fixed-size and store primitives, while Collections are dynamic and store objects. The document also highlights the performance characteristics and use cases for each data structure.

Uploaded by

galandedikasha03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Java_Assignment_Comparisons

The document outlines key differences between various Java data structures and concepts, including Arrays vs Collections, ArrayList vs LinkedList, List vs Set, Collection vs Collections, and Comparable vs Comparator. Arrays are fixed-size and store primitives, while Collections are dynamic and store objects. The document also highlights the performance characteristics and use cases for each data structure.

Uploaded by

galandedikasha03
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Java Concepts Assignment

1. Array vs Collection:

- Array is a fixed-size data structure that stores elements of the same type.

- Collection is part of the Java Collections Framework and provides dynamic storage.

- Arrays can store primitives; Collections store only objects.

- Collections provide utility methods; Arrays do not.

2. ArrayList vs LinkedList:

- ArrayList uses a dynamic array; LinkedList uses a doubly linked list.

- ArrayList offers fast random access; LinkedList is better for frequent insertions/deletions.

- ArrayList shifting makes insertion/removal slower than LinkedList.

3. List vs Set:

- List allows duplicates and maintains insertion order.

- Set does not allow duplicates and may not maintain order (e.g., HashSet).

- Common List: ArrayList, LinkedList; Set: HashSet, TreeSet.

4. Collection vs Collections:

- Collection is an interface (root of List, Set, etc.).

- Collections is a utility class with static methods like sort(), reverse().

5. Comparable vs Comparator:

- Comparable defines natural ordering within the class via compareTo().

- Comparator defines custom sorting logic outside the class via compare().

- Comparable modifies class; Comparator adds flexibility for different sort logics.

You might also like