当前位置:网站首页>[List Exercise] Traverse the collection and sort by price from low to high,
[List Exercise] Traverse the collection and sort by price from low to high,
2022-08-10 05:51:00 【hagong9】
package com.zhang.list_;import java.util.ArrayList;import java.util.List;public class ListTestBook {public static void main(String[] args) {List list = new ArrayList();list.add(new Books("Three Kingdoms",200));list.add(new Books("Journey to the West",81));list.add(new Books("Water Margin",108));for (Object o :list) {System.out.println(o);}System.out.println("======After sorting========");sort(list);for (Object o :list) {System.out.println(o);}}public static void sort(List list){for (int i = 0;i < list.size()-1;i++){for (int j = 0;j < list.size()-1-i;j++){//Take out the object Book and downcastBooks book1 = (Books) list.get(j);Books book2 = (Books) list.get(j+1);if (book2.getPrice() < book1.getPrice()){list.set(j,book2);list.set(j+1,book1);}}}}}class Books{public Books() {}@Overridepublic String toString() {return "name:"+name+",price:"+price;}private String name;private int price;public Books(String name, int price) {this.name = name;this.price = price;}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getPrice() {return price;}public void setPrice(int price) {this.price = price;}}
边栏推荐
- Consensus calculation and incentive mechanism
- IO stream【】【】【】
- el-dropdown下拉菜单样式修改,去掉小三角
- 网络安全5
- Count down the six weapons of the domestic interface collaboration platform!
- 最新最全的数字藏品发售日历-07.27
- 微信小程序wx.writeBLECharacteristicValue汉字转buffer问题
- Chained Picks: Starbucks looks at digital collectibles and better engages customers
- 链读 | 最新最全的数字藏品发售日历-07.28
- 连接 Nacos 报超时错误
猜你喜欢

训练集Loss收敛,但是测试集Loss震荡的厉害?

链读精选:星巴克着眼于数字收藏品并更好地吸引客户

tinymce富文本编辑器

深度学习模型训练前的必做工作:总览模型信息

I use this recruit let the team to improve the development efficiency of 100%!

The latest and most complete digital collection sales calendar-07.26

IO流【】【】【】

文章复现:超分辨率网络FSRCNN

【笔记】集合框架体系 Collection

Database Notes Create Database, Table Backup
随机推荐
Chained Picks: Starbucks looks at digital collectibles and better engages customers
Ten years of sharpening a sword!The digital collection market software, Link Reading APP is officially open for internal testing!
Privatisation build personal network backup NextCloud
你不知道的常规流
Smart contracts and DAPP decentralized applications
IDEA 项目中设置 Sources Resources 等文件夹
网络安全5
用Pytorch从0到1实现逻辑回归
transaction, storage engine
Count down the six weapons of the domestic interface collaboration platform!
Mockito基本使用指南
el-dropdown drop-down menu style modification, remove the small triangle
最新最全的数字藏品发售日历-07.26
redis---非关系型数据库(NoSql)
el-cascader级联选择器的子菜单双击两次才显示被选中的内容
常用类 BigDecimal
小记录:Pytorch做深度学习必要加载的包
Bifrost micro synchronous database implementation services across the library data synchronization
训练集Loss收敛,但是测试集Loss震荡的厉害?
IDEA的database使用教程(使用mysql数据库)