Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Chris Avila
Greenhorn
Posts: 8
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
Sheriff
Posts: 35976
422
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: 8
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: 1627
21
  • 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
 
What are you doing? You are supposed to be reading this tiny ad!
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!