I have written the program as follows. I want to sort the linked list on basis of the String a
in the class player.
now the output is
nagpur rathi
akola ashwin
but after sorting with the variable a
it should be
akola ashwin
nagpur rathi
The code is as follows:
package link.demo;
public class Player
{
String a,b;
Player()
{
}
Player(String city,String name)
{
a=city;
b=name;
}
}
package link.demo;
import java.util.Iterator;
import java.util.LinkedList;
public class Linkdemo
{
/**
* @param args the command line arguments
*/
public static void main(String[] args)throws Exception
{
// TODO code application logic here
Player b=new Player("nagpur","rathi");
Player c=new Player("akola","ashwin");
//player temp=new player();
LinkedList<Player> l= new LinkedList<Player>();
l.add(b);
l.add(c);
Iterator<Player> itr=l.iterator();
while(itr.hasNext())
{
Player temp=itr.next();
System.out.println(temp.a+" "+temp.b);
}
}
}