• Post Reply Bookmark Topic Watch Topic
  • New Topic

Need Help  RSS feed

 
bob morkos
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ICPair[] data =
{
new ICPair(28, 'h'),
new ICPair(29, 'c'),
new ICPair(2, 'a'),
new ICPair(3, 'b'),
new ICPair(5, 't'),
new ICPair(8, 'p'),
new ICPair(99, 'm'),
};
The above code needs to be changed to something like the code below.

List ll = new ArrayList();
ll.add(new ICPair(28, 'h'));
ll.add(new ICPair(29, 'c'));
ll.add(new ICPair(2, 'a'));
ll.add(new ICPair(3, 'b'));
ll.add(new ICPair(5, 't'));
ll.add(new ICPair(8, 'p'));
ll.add(new ICPair(99, 'm'));
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bob,
What's your question?
 
bob morkos
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer :
List ll = new ArrayList();

ll.add(new ICPair(28, 'h'));
ll.add(new ICPair(29, 'c'));
ll.add(new ICPair(2, 'a'));
ll.add(new ICPair(3, 'b'));
ll.add(new ICPair(5, 't'));
ll.add(new ICPair(8, 'p'));
ll.add(new ICPair(99, 'm'));


Object[] data = ll.toArray();


Arrays.sort(data);
System.out.println("AFTER:");
for (int i = 0; i < data.length; ++i) {

System.out.println("" + ((ICPair)data[i]).getId() + " : " + ((ICPair)data[i]).getC() );
}

Originally posted by bob morkos:
ICPair[] data =
{
new ICPair(28, 'h'),
new ICPair(29, 'c'),
new ICPair(2, 'a'),
new ICPair(3, 'b'),
new ICPair(5, 't'),
new ICPair(8, 'p'),
new ICPair(99, 'm'),
};
The above code needs to be changed to something like the code below.

List ll = new ArrayList();
ll.add(new ICPair(28, 'h'));
ll.add(new ICPair(29, 'c'));
ll.add(new ICPair(2, 'a'));
ll.add(new ICPair(3, 'b'));
ll.add(new ICPair(5, 't'));
ll.add(new ICPair(8, 'p'));
ll.add(new ICPair(99, 'm'));
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!