• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

What it means

 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1> comparable :

you must modify the class whose instance you want to sort

2> comparator:

you build a class separate from the class whose instance want to sort
I am not getting this point anybody please explain *******8

3> there is method for converting Arrays to List and vice versa


but list is interface then how we can store array value to this List (slist)???


 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

but list is interface then how we can store array value to this List (slist)???



Arrays are objects, and lists works with objects. So, if you have a collection that is a list, then it can be used to store arrays (of course, in this case, the list that is returned is fixed sized).

Henry
 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well i hope you understand why we define an arraylist like this
List<E> l = new Arraylist<E>();<--< this means the array list is referred from List Reference variable.We can use the superclass type to declare a reference variable.

Now from the Arrays.aslist(), we get a List<E> return type. So it should be stored in a reference type which is of the type List<E> means a reference bitpattern of the type List is returned and not the entire object so we take that bitpattern and store it in the List type only. But internally how the array is converted to list and what list type is used is encapsulated and i guess you don't need to worry about that.

About comparable, the sort method that is used for collections is used to compare the objects of the list i.e this object with the list passed as an argument. String and Wrapper classes have implemented the comparable interface so we don't need to implement it again. But if we use our own class (<classname>), what is that should be compared and how? that thing is specified by using a comparable and that should be done for the mutually comparable class.

Comparator is a specific role that you specify for that collection. Take ordering and sorting. Order can be any thing but when sorting is done its done with a specific rule. Using Comparator, we can specify how the objects should be compared and on what basis.
 
vineet walia
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitish Bangera wrote:well i hope you understand why we define an arraylist like this
List<E> l = new Arraylist<E>();<--< this means the array list is referred from List Reference variable.We can use the superclass type to declare a reference variable.

Now from the Arrays.aslist(), we get a List<E> return type. So it should be stored in a reference type which is of the type List<E> means a reference bitpattern of the type List is returned and not the entire object so we take that bitpattern and store it in the List type only. But internally how the array is converted to list and what list type is used is encapsulated and i guess you don't need to worry about that.

About comparable, the sort method that is used for collections is used to compare the objects of the list i.e this object with the list passed as an argument. String and Wrapper classes have implemented the comparable interface so we don't need to implement it again. But if we use our own class (<classname>), what is that should be compared and how? that thing is specified by using a comparable and that should be done for the mutually comparable class.

Comparator is a specific role that you specify for that collection. Take ordering and sorting. Order can be any thing but when sorting is done its done with a specific rule. Using Comparator, we can specify how the objects should be compared and on what basis.


thanks Nitish bro
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic