• Post Reply Bookmark Topic Watch Topic
  • New Topic

Arrays.sort method  RSS feed

 
Bari Clark
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am confused about the following (see commented line below):

import java.util.Arrays;
String[] colors = {"red", "yellow", "blue"};
Arrays.sort(colors);  // This is what confuses me. Why wouldn't you write: colors.sort();
 
Stephan van Hulst
Saloon Keeper
Posts: 7993
143
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to CodeRanch!

colors is an array, and arrays don't have the sort() method defined on them.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!