Results 1 to 3 of 3
  1. #1
    girlycoder is offline Member
    Join Date
    May 2016
    Posts
    4
    Rep Power
    0

    Question The use of Comparable Interface In Java?

    I am learning java and I still don't know a lot of things about Java.

    Currently I am doing an example project and there, I need to sort certain objects. My friend told me to use Comparable interface for this.
    So, I looked for it and Oracle says-
    Lists (and arrays) of objects that implement this interface can be sorted automatically by Collections.sort (and Arrays.sort). Objects that implement this interface can be used as keys in a sorted map or as elements in a sorted set, without the need to specify a comparator.
    I don't understand this, can some one explain or give me any good resources where I can know more about Comparable Interface?

    Thanks in advance
    Last edited by girlycoder; 05-08-2016 at 10:20 AM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: The use of Comparable Interface In Java?

    If you are learning about Java you should bookmark two links. The API documentation
    and the tutorials (see my signature). In the tutorials there is a section on
    ordering. It discusses the comparable interface.

    You said you were learning Java. There are quite a few basics to learn before worrying
    about sorting. Do you understand interfaces in general? Are you familiar with Strings, ints, double
    etc? Object types vs primitive types? My recommendation (assuming you have not read and experimented)
    is to focus on the fundamentals first.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    girlycoder is offline Member
    Join Date
    May 2016
    Posts
    4
    Rep Power
    0

    Default Re: The use of Comparable Interface In Java?

    Thanks a lot for your answer
    Yes, I have basic idea about java/OOP in general. But I did not see the tutorials thoroughly.
    You gave me exact tutorial link I was looking for.
    Meanwhile, I got this link, which helped me a lot.
    I got it from another site I asked help from.

Similar Threads

  1. Comparable and Iterable Interface
    By ahanslot in forum New To Java
    Replies: 19
    Last Post: 01-06-2014, 01:48 PM
  2. again the Comparable interface
    By willemjav in forum Advanced Java
    Replies: 11
    Last Post: 07-09-2013, 01:59 PM
  3. Comparable interface
    By diamonddragon in forum New To Java
    Replies: 17
    Last Post: 02-01-2012, 12:07 AM
  4. Implement Comparable interface
    By JojoDiaz in forum New To Java
    Replies: 3
    Last Post: 11-07-2011, 07:10 AM
  5. Comparable Interface
    By Yelrubk in forum New To Java
    Replies: 3
    Last Post: 04-28-2010, 02:46 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •