import java.util.*;
class Book
{
int id;
String title;
Book(int id, String title)
{
this.id=id;
this.title=title;
}
public String toString()
{
return id+" "+title;
}
}
public class BookDemo
{
public static void main(String args[])
{
List<Book> ar= new ArrayList<Book>();
ar.add(new Book(1,"java"));
ar.add(new Book(2,"C"));
Comparator<Book> com = new Comparator<Book>()
{
public int compare(Book ob1, Book ob2)
{
if(ob1.title.compareTo(ob2.title)>0)
return 1;
else
return -1;
}
};
Collections.sort(ar,com);
for(Book b:ar)
System.out.println(b);
}
}
==========================================================
import java.util.*;
class Book implements Comparable<Book>
{
int id;
String title;
Book(int id, String title)
{
this.id=id;
this.title=title;
}
public String toString()
{
return id+" "+title;
}
public int compareTo(Book ob2)
{
if(this.title.compareTo(ob2.title)>0)
return 1;
else
return -1;
}
}
public class BookDemo
{
public static void main(String args[])
{
List<Book> ar= new ArrayList<Book>();
ar.add(new Book(1,"java"));
ar.add(new Book(2,"C"));
Collections.sort(ar);
for(Book b:ar)
System.out.println(b);
}
}
This was really a very informative post and I am glad to offer a similar information by which you can create more Animated explainer videos
ReplyDeleteAn animated explainer video company grasp your business ideas and translate them into animated explainer videos or live videos crafted with thoughtful messaging. A creative design team, Explainer video production company can come up with the proper sort of video as per our client’s approach. Be it for a product, a replacement venture you’re foraying into or anything that’s tough to elucidate to your audience , our team is adept at creating an animated video for business in multiple languages to support their vernacular requirements.