0% found this document useful (0 votes)
3 views3 pages

Collection Java Questions

The document provides links to various resources explaining key concepts in Java collections, including iteration methods, differences between collection classes like ArrayList, LinkedList, Vector, HashSet, HashMap, and Hashtable, as well as interfaces like Iterator and Enumeration. It also covers sorting elements using Comparable and Comparator interfaces, and clarifies the distinction between Java collection and Java collections. Each topic is linked to a detailed explanation for further reading.

Uploaded by

hackers.iknow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Collection Java Questions

The document provides links to various resources explaining key concepts in Java collections, including iteration methods, differences between collection classes like ArrayList, LinkedList, Vector, HashSet, HashMap, and Hashtable, as well as interfaces like Iterator and Enumeration. It also covers sorting elements using Comparable and Comparator interfaces, and clarifies the distinction between Java collection and Java collections. Each topic is linked to a detailed explanation for further reading.

Uploaded by

hackers.iknow
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

What are the two ways to iterate the elements of a collection?

https://www.javatpoint.com/how-to-iterate-list-in-java

What is the difference between ArrayList and LinkedList classes in collection framework?

https://www.javatpoint.com/difference-between-arraylist-and-linkedlist

What is the difference between ArrayList and Vector classes in collection framework?

https://www.javatpoint.com/difference-between-arraylist-and-vector

What is the difference between HashSet and HashMap classes in collection framework?

https://www.javatpoint.com/difference-between-hashset-and-hashmap

What is the difference between HashMap and Hashtable class?

https://www.javatpoint.com/difference-between-hashmap-and-hashtable

What is the difference between Iterator and Enumeration interface in collection framework?

https://www.tutorialspoint.com/difference-between-iterator-and-enumeration-in-java

How can we sort the elements of an object? What is the difference between Comparable and
Comparator interfaces?

To sort elements of an object in Java:

1. **Using `Comparable`**:

- Implement the `Comparable` interface in your class.

- Override the `compareTo` method.

```java

class Person implements Comparable<Person> {

String name;

int age;

@Override
public int compareTo(Person other) {

return this.name.compareTo(other.name); // Sorting by name

Collections.sort(listOfPersons);

```

2. **Using `Comparator`**:

- Create a `Comparator` and override the `compare` method.

```java

Comparator<Person> byAge = new Comparator<Person>() {

@Override

public int compare(Person p1, Person p2) {

return Integer.compare(p1.age, p2.age); // Sorting by age

};

Collections.sort(listOfPersons, byAge);

```

3. **For arrays**:

- Use `Arrays.sort()`.

```java

Arrays.sort(arrayOfPersons);

```

https://www.javatpoint.com/difference-between-comparable-and-comparator

What does the hashcode() method?

https://www.javatpoint.com/java-integer-hashcode-method
What is the difference between Java collection and Java collections?

https://www.geeksforgeeks.org/collection-vs-collections-in-java-with-example/

You might also like