【发布时间】:2021-11-11 17:35:21
【问题描述】:
(我是初学者,所以如果我说错了,请纠正我) 我从不同的对象制作了一个 ArrayList。但我不知道如何更改 ArrayList 上的特定对象。例如,在下面的示例中将人口从 80 更改为 85。 承包商:
class constructor {
private Contry contry;
private BigDecimal population;
private String capital ;
public constructor(Contry contry, BigDecimal population, String capital){
this.contry = contry;
this.population = population;
this.capital = capital;
}
和我的方法:
public class ContryInfo {
public List<constructor> information(Contry contry, BigDecimal population,
String capital) {
List<constructor> contriesInfo = new ArrayList<>();
contriesInfo.add(new constructor(contry, population, capital));
return Information
和我的主要
public static void main(String[] args) {
List<constructor> exampleList = new ArrayList<>();
exampleList = new ContryInfo().Information(Germany, new BigDecimal("80"), "Berlin");
我尝试使用 stream().map 但没有成功找到方法。如果你们写出我的问题的解决方案,我会很高兴。
【问题讨论】:
-
在尝试此操作之前,您应该学习有关 Java 基础知识的教程或教科书。您不了解构造方法的基础知识,也不了解基本的 Java 命名约定。对这个网站来说不是一个好问题。
标签: java object arraylist stream set