Win a copy of Getting started with Java programming language this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Can Collections.sort(arg1, arg2) contain an array as it's first argument?  RSS feed

 
Chris Avila
Greenhorn
Posts: 14
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unsure if  Collections.sort(arg1, arg2) contain an array as it's first argument? The reasom is that I know for a fact that this first arguement can be a list (List,ArraysList,etc), but when I try using a simple array, it is not accepted as a valid parameter. Is it just that Collections.sort(arg1, arg2) cannot accept a regular array? My professor gave us instructions to use a regular array but I do not think this is possible using Collections.sort(arg1, arg2). Thanks in advance!
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 36171
439
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris
No. Collections.sort() cannot take an array. There's an Arrays.sort() method that does take an array.
 
Chris Avila
Greenhorn
Posts: 14
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks @Jeanne Boyarsky ! Really just needed to make sure. My professors instructions were a tid bit unclear Appreciate it!
 
Norm Radder
Rancher
Posts: 1733
22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also take a look at the API doc for the Collections class to see what are valid args for the sort method.
http://docs.oracle.com/javase/8/docs/api/index.html
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!