<pre class="cpp" name="code"><img src="//img-blog.csdn.net/20171130174554451" alt="">package Kuang;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
List<Book> bookList = new ArrayList<Book>();
bookList.add(new Book("英语", 29.99));
bookList.add(new Book("数学", 50));
bookList.add(new Book("化学", 30));
bookList.add(new Book("生物", 30));
bookList.add(new Book("历史", 30));
System.out.println("请输入价格:\n");
Book book = new Book("对比价格", 50);
System.out.println(book.name + book.price);
for (int i = 0; i < bookList.size(); i++
{
if (book.compareTo(bookList.get(i)
System.out.println((bookList.get(i)
}System.out.println("价格相同的:"+(book.price));
}
}</pre><br>
package Kuang;public class Book implements Comparable<Book>{String name;Double price;public Book (String nm,double p){name=nm;price=p;}@Overridepublic int compareTo(Book o) {
<pre></pre>
<br>
posted @
2017-12-10 19:55
北有孤鹜
阅读(
318 )
评论()
编辑
收藏
举报