关于 List 删除元素的笔记 作者: Chuwen 时间: 2020-10-15 分类: Java 评论 # 有以下代码 > 个人理解,可能有错 `MiBean.java` ``` public class MiBean { private int id; private String name; public MiBean(int id, String name) { this.id = id; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } ``` ``` List miBeanLists = new ArrayList<>(); miBeanLists.add(new MiBean(9, "小米 10")); miBeanLists.add(new MiBean(8, "小米 10 Pro")); miBeanLists.add(new MiBean(7, "小米 10 Ultra")); miBeanLists.add(new MiBean(12, "Redmi K30 Pro")); miBeanLists.add(new MiBean(11, "Redmi K30 5G")); miBeanLists.add(new MiBean(10, "Redmi K30 4G")); //我以为可以直接遍历,然后调用 remove 方法移除 for(int i=0; i 究其原因,原来是当删除之后 `i 因为我们之前删除了一个,所以在删除之后加一句 i--; 就可以全部删除了 --- > 复制别人总结的 >> 在代码中,删除元素后,需要把下标减一。这是因为在每次删除元素后,ArrayList会将后面部分的元素依次往上挪一个位置(就是copy),所以,下一个需要访问的下标还是当前下标,所以必须得减一才能把所有元素都遍历完
Java 使用 Collections.sort() 排序 作者: Chuwen 时间: 2020-10-12 分类: 其他分类 评论 > 只是记录下笔记 # RechargeHistoryList.class ``` public class RechargeHistoryList { private int id; private int carId; private int rechargeVal;//充值金额 private String rechargeDate; public RechargeHistoryList(int carId, int rechargeVal, String rechargeDate) { this.carId = carId; this.rechargeVal = rechargeVal; this.rechargeDate = rechargeDate; } public int getId() { return id; } public void setId(int id) { this.id = id; } public int getCarId() { return carId; } public void setCarId(int carId) { this.carId = carId; } public int getRechargeVal() { return rechargeVal; } public void setRechargeVal(int rechargeVal) { this.rechargeVal = rechargeVal; } public String getRechargeDate() { return rechargeDate; } public void setRechargeDate(String rechargeDate) { this.rechargeDate = rechargeDate; } } ``` # 代码 ``` ArrayList rechargeHistoryLists = new ArrayList<>(); rechargeHistoryLists.add(new GechargeHistoryLists(1, 100, "2020-10-12 09:35:20")) rechargeHistoryLists.add(new GechargeHistoryLists(2, 50, "2020-10-12 09:35:20")) Collections.sort(rechargeHistoryLists, new Comparator() { @Override public int compare(RechargeHistoryList o1, RechargeHistoryList o2) { return -(o1.getRechargeVal() - o2.getRechargeVal());//根据充值金额 “降序” 排序 //return o1.getRechargeVal() - o2.getRechargeVal();//根据充值金额 “升序” 排序 } }); ```
使用 GsonFormat 解析数组形式的 json 作者: Chuwen 时间: 2020-10-12 分类: Android,Java 评论 > 记下笔记,以访忘记 # 假设有以下数据 ``` [{ "CarId": 1, "Time": "2017-11-26 16:58:11", "Cost": 10 }, { "CarId": 1, "Time": "2017-11-26 16:58:19", "Cost": 20 }, { "CarId": 1, "Time": "2017-11-26 16:58:24", "Cost": 30 }, { "CarId": 1, "Time": "2017-11-26 16:58:28", "Cost": 40 }] ``` # 以下类 ``` public class GetCarAccountRecord { /** * CarId : 1 * Time : 2017-11-26 04:58:11 * Cost : 10 */ private int CarId; private String Time; private int Cost; public int getCarId() { return CarId; } public void setCarId(int CarId) { this.CarId = CarId; } public String getTime() { return Time; } public void setTime(String Time) { this.Time = Time; } public int getCost() { return Cost; } public void setCost(int Cost) { this.Cost = Cost; } } ``` # 使用 Gson 解析,然后遍历输出 ``` List list = new Gson().fromJson(jsonObject.optJSONArray("ROWS_DETAIL").toString(), new TypeToken>() {}.getType()); for (GetCarAccountRecord getCarAccountRecord : list) { Log.i("小车编号:", String.valueOf(getCarAccountRecord.getCarId())); Log.i("充值金额:", String.valueOf(getCarAccountRecord.getCost())); } ```
Windows 安装 Ubuntu 系统(子系统),报错 WslRegisterDistribution failed with error: 0x8007019e 作者: Chuwen 时间: 2020-09-13 分类: 其他分类 评论 # 错误一:Error Code: 0x8007019e `WslRegisterDistribution failed with error: 0x8007019e` 这是因为系统未安装Windows子系统支持。 解决办法: 1. 键盘行按键 Win+x,选择 **Windows PowerShell(管理员)** 2. 输入 `Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux` 3. 按回车,然后输入Y并重启。 重启打开Ubuntu的命令窗口,等几分钟,输入账户和密码即可。
小米充电功率检测App (需要 ROOT 权限) 作者: Chuwen 时间: 2020-08-29 分类: 唠嗑闲聊 评论 # 小米充电功率检测 欢迎加群 `1006294793` 反馈,谢谢! # v0.51 (最新版) > 2020-08-29 17:16 发布 > > 1. 解决无法安装问题 下载链接:https://nowtime.lanzous.com/izLO4g6j5pg # V0.50 > 2020-08-29 15:48 发布 > > 该版本无法安装,请勿下载 ~~下载链接:https://nowtime.lanzous.com/izwleg6givc~~ ---