Breaking News: Grepper is joining You.com. Read the official announcement!
Check it out

What are the important points to remember while using Java Collections Framework

Pragya Keshap answered on February 4, 2023 Popularity 1/10 Helpfulness 1/10

Contents


More Related Answers

  • Which is the most important class in Java?
  • What are the main benefits of Collections Framework in Java?

  • What are the important points to remember while using Java Collections Framework

    0

    Some of the important points to remember while using Java

    Collections Framework are:

    1. Interfaces: For Collections, we should write code with

    generic interfaces instead of concrete implementation. Due

    to this we maintain the flexibility of changing the

    implementation at a later point of time.

    2. Generics: We should use Generics for type-safety and to

    avoid ClassCastException at runtime.

    3. Collections: It is recommended to use Collections utility

    class for algorithms and various other common methods

    for Collections.

    4. Right Type: We have to choose the right type of Java

    collection based on our need. If size is fixed, we can use

    Array over ArrayList. If we do not want duplicate

    elements we use Set.

    If we need the ability to iterate the elements of a Map in

    the order of insertion then we use a TreeMap.

    5. Initial Size: In some collection classes we can specify the

    initial size/capacity. Therefore we should have an estimate

    of number of elements in a Collection before deciding the

    right collection type. We can use it to avoid rehashing or

    resizing.

    6. Map: We should use immutable classes provided by Java

    as key elements in a Map

    https://www.javatpoint.com/collections-in-java#:~:text=The%20Collection%20in%20Java%20is,a%20single%20unit%20of%20objects.

    Popularity 1/10 Helpfulness 1/10 Language java
    Source: Grepper
    Link to this answer
    Share Copy Link
    Contributed on Feb 04 2023
    Pragya Keshap
    0 Answers  Avg Quality 2/10


    X

    Continue with Google

    By continuing, I agree that I have read and agree to Greppers's Terms of Service and Privacy Policy.
    X
    Grepper Account Login Required

    Oops, You will need to install Grepper and log-in to perform this action.