0% found this document useful (0 votes)
5 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)
5 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

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

[Link]

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

[Link]

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

[Link]

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

[Link]

What is the difference between HashMap and Hashtable class?

[Link]

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

[Link]

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 [Link]([Link]); // Sorting by name

[Link](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 [Link]([Link], [Link]); // Sorting by age

};

[Link](listOfPersons, byAge);

```

3. **For arrays**:

- Use `[Link]()`.

```java

[Link](arrayOfPersons);

```

[Link]

What does the hashcode() method?

[Link]
What is the difference between Java collection and Java collections?

[Link]

You might also like