Java 从由不同对象组成的对象中提取字符串数组
我是java新手。对你们中的许多人来说,这可能是一个愚蠢的问题。 但是我很震惊,所以请帮助我。我想做点什么。我正在使用下面两个类。我在这里定义java代码 公营阶层人士{Java 从由不同对象组成的对象中提取字符串数组,java,arrays,object,multidimensional-array,Java,Arrays,Object,Multidimensional Array,我是java新手。对你们中的许多人来说,这可能是一个愚蠢的问题。 但是我很震惊,所以请帮助我。我想做点什么。我正在使用下面两个类。我在这里定义java代码 公营阶层人士{ private int id, id100px; private String rollNumber; private String mobile_number, email_id, nick_name, hobbies, dob, name; private Testimony[] testimony; publ
private int id, id100px;
private String rollNumber;
private String mobile_number, email_id, nick_name, hobbies, dob, name;
private Testimony[] testimony;
public People(String name, int id, String mobile_number, String email_id, Testimony ... testimony) {
this.name = name;
this.id = id;
this.mobile_number = mobile_number;
this.email_id = email_id;
this.testimony = testimony;
}
public Testimony[] getTestimony() {
return testimony;
}
public String getEmail_id() {
return email_id;
}
public int getId() {
return id;
}
public String getMobile_number() {
return mobile_number;
}
public String getName() {
return name;
}
}
及
现在,我需要提取People类中每个条目的每个数据。我正在使用getMethods处理所有事情。
我在提取证词对象的数据时遇到问题,我需要仅为一个特定对象或人员类提取并保存证词类的字符串证词[],因为证词是构造函数中的变量arg
证词…证词
您必须定义一个getter,如:
public Testimony[] getTestimony()(
}
对于setter,可以应用相同的逻辑:
public void setTestimony(Testimony[] testimony){
this.Testimony = testimony;
}
更新: 如果您需要每个证词中的信息,您可以定义打印这些信息的方法:
public void printAllTestimonies(){
for (Testimony testim : testimony) {
System.out.println("Testimony: "+ testim.gettestimony());
System.out.println("Name: "+ testim.getname());
System.out.println("Id: "+ testim.getid());
}
}
public void printAllTestimonies(){
for (Testimony testim : testimony) {
System.out.println("Testimony: "+ testim.gettestimony());
System.out.println("Name: "+ testim.getname());
System.out.println("Id: "+ testim.getid());
}
}