• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

comparable question

 
Everett Chan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am seeking for help on a Comparable question, if anybody can provide any insight I'd greatly appreciate it.

I have an int array and a method that takes in (Comparable[] array), what could I do to make the Comparable[] accepts the int array? Do I have to change the int array to an array of Integer Objects? Or is there another way I can tackle this?

Thank you very much,
Everett Chan
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Everett,

Welcome to JavaRanch!

On the face of it, yes, making an array of Integer could be one easy solution. Alternatively, you could make a copy of that method that takes an array of Comparable, and modify it to work with ints. If c is an array of Comparable and i is an array of ints, then c[n].compareTo(c[m]) translates directly into i[n] - i[m].
 
Everett Chan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much.

What is this forum's policy on someone posting a segment of their code to ask for help?

e.g. me posting my reverse int array and asking for help to turn them into Integer Object-based.

Thank you for all the help,
Everett
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome to post code. We appreciate it if you keep the code as short as possible -- i.e., don't post code for a GUI with 100 buttons if you're asking about JDBC -- and if you use the UBB [C0DE][/C0DE] tags to surround the code to preserve the formatting.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic