** он показывает мне то же самое время 23 мая 1986 г. Выход ... Лицо 0: Джон Дэвидсон, 23 мая 1986 года, Белград; Лицо 1: Майкл Бартон, 23 мая 1986 года, Краков; Человек 2: Иван Перкинсон, 23 мая 1986, Москва; **Как я могу получить время для каждого имени?
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class Persons {
public String name;
public String lastName;
public String Birthplace;
public static String dateBirth;
Persons(String name, String lastName, String Birthplace, String dateBirth) {
this.name = name;
this.lastName = lastName;
this.Birthplace = Birthplace;
Persons.dateBirth = dateBirth;
}
public String getName() {
return name;
}
public String getLastName() {
return lastName;
}
public String getPlace() {
return Birthplace;
}
public String getDateBirth() {
return dateBirth;
}
public void setDateBirth(String dateBirth) {
Persons.dateBirth = dateBirth;
}
public static void main(String[] args) throws ParseException {
SimpleDateFormat formatter = new SimpleDateFormat("dd ',' MMM yyyy", Locale.ENGLISH);
SimpleDateFormat parser = new SimpleDateFormat("ddMMyyyy");
List<Persons> details = new ArrayList<Persons>();
String text = "John.Davidson/05051988/Belgrade Michael.Barton/01011968/Krakov Ivan.Perkinson/23051986/Moscow";
String[] personsSplit = text.split(" ");
for (int i = 0; i < personsSplit.length; i++) {
String[] personList = personsSplit[i].split("/");
String[] print = personList[0].split("\\.");
Persons newPerson = new Persons(print[0], print[1],
personList[2], personList[1]);
details .add(newPerson);
}
for (int i = 0; i <details .size(); i++) {
String outputString = "Person " + i + ": "
+ details .get(i).getName() + " "
+ details .get(i).getLastName() + ", "
+formatter.format(parser.parse(dateBirth)) + ", "
+ details .get(i).getPlace() + ";";
System.out.println(outputString);
}
}
}
Почему бы не 'this.dateBirth = dateBirth;'? –
Вы вообще не объяснили свой вопрос. – rodit
@UmaKanth, потому что dateBirth является статическим свойством без причины. – MCMastery