gpt4 book ai didi

java - 迭代对象/列表

转载 作者:行者123 更新时间:2023-12-01 16:15:31 25 4
gpt4 key购买 nike

我编写所有类(class)是为了更好地理解我想要实现的目标。我遇到循环问题,或者是否有其他选项。我感到困惑的是,目前我的索引设置为 0。我如何循环列表并执行功能

if(empgrouping = group-A){use group-A position and ID} 
else
if(empgrouping = group-B){use group-B position and ID}
<小时/>
private Employeesset employeesset (String personal, String empgrouping) throws Exception{
Employeesset emp = new Employeesset();

Details details = employeeconfig.getempdepts().get(0);

if(emp.flagistrue()&&empgrouping.equals(“group-A”){
emp.setemplgroup(empgrouping);
emp.setposition(“”);
emp.setidentification(“”);
}else{
// choose group b or c//

——————————————————

“employee_details”:[
{“Employees “: ”group-A“,
“Position “: ”management“,
“ID “: ”333iisdsa“,
“Environments” :
[  
    "name":"Shyam",   
    "name":"Bob", 
    "name":"Jai"
]} ,
{"Employees “: ”group-B”,
“Position “: ”management“,
“ID “: ”4455iisdf“,
“Environments” :
[  
      "name”:”sam”, 
    "name”:”loki”,  
    "name”:”avenger” 
]},
{"Employees “: ”group-c“,
“Position “: ”management“,
“ID “: ”234kkdk“,
“Environments” : [  
    "name”:”super”, 
    "name”:”kam”,  
    "name”:”mike”
]}    
]

———————————————

public static class Details{
@Jsonproperty(“Employees”)
String emptype;

@Jsonproperty(“Position”)
String position;

@Jsonproperty(“ID”)
String identification;

@Jsonproperty(“environments”)
List<Environments> environments;

//Getters and setters//

———————————

public class employeeconfig{
@Jsonproperty(“employee_details”);
List<Details> empdepts;

//getters and setters//

——————————————

public class Employeesset{
private employee;
private position;
private identification;

//getters and setters//

最佳答案

首先,您需要更改您编写的类Employeesset的整个代码结构,它应该是EmployeesSet然后方法应该始终遵循与变量相同的驼峰式大小写结构

private EmployeesSet employeesSet (String personal, String empGrouping) throws Exception{
EmployeesSet emp = new EmployeesSet();

employeeConfig.getempdepts().foreach(resultDetails->{

//Write your code logic here //Using jdk 8
}

if(emp.flagistrue()&&empGrouping.equals(“group-A”){
emp.setemplgroup(empGrouping);
emp.setposition(“”);
emp.setidentification(“”);
}else{

关于java - 迭代对象/列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62401171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com