Parsing text and creating a collection of objects

The following string is given, which is a record read from a outer source:
String text = "John.Davidson/05051988/Belgrade
Michael.Barton/01011968/Krakov Ivan.Perkinson/23051986/Moscow";

It is necessary to create a logic that will extract data from this record:
Data needed:
    - name
    - lastname
    - date of birth
    - place of birth
Read and extracted data from the string needs to be used for filling the fields of the Person type object; therefore, it is necessary to create a class Person, as well as the appropriate fields within it. So, in the class Person should be a constructor with these 4 given fields.
Then, in the Test class, after creating an object and filling in his fields, the Person type object should be placed in a collection (for example, in the list) and finally go through that collection and print data about people.
The date of birth field should be LocalDate type. When printing data on people, in the end, it would be desirable to format the print, so that a date is shown in the form: May 5. 2014 .

Created on: Jan 14, 2017. 

Person.java
1:  import java.time.LocalDate;  
2:  import java.time.format.DateTimeFormatter;  
3:    
4:  public class Person {  
5:      
6:    public String name;  
7:    public String lastname;  
8:    public LocalDate dateOfBirth;  
9:    public String placeOfBirth;  
10:      
11:    public Person (String name, String lastname, String placeOfBirth, LocalDate dateOfBirth) {  
12:      this.name = name;  
13:      this.lastname = lastname;  
14:      this.placeOfBirth = placeOfBirth;  
15:      this.dateOfBirth = dateOfBirth;  
16:    }  
17:      
18:    @Override  
19:    public String toString() {  
20:      DateTimeFormatter form2 = DateTimeFormatter.ofPattern("dd.MMM yyyy.");  
21:      return ( "Name: " + name + " / " + "Lastname: " + lastname + " / " +   
22:          "Date of birth: " + dateOfBirth.format(form2) + " / " +   
23:          "Place of birth: " + placeOfBirth);  
24:    }  
25:      
26:  }  

Test.java 

1:  import java.time.LocalDate;  
2:  import java.time.format.DateTimeFormatter;  
3:  import java.util.ArrayList;  
4:    
5:  public class Test {  
6:    
7:    public static void main(String[] args) {  
8:      String text = "John.Davidson/05051988/Belgrade Michael.Barton/01011968/Krakov Ivan.Perkinson/23051986/Moscow";  
9:      String [] textArray = text.split(" ");  
10:      ArrayList personList = new ArrayList();  
11:        
12:      for (int i=0; i<textArray.length; i++){        
13:        String [] textArray2 = textArray[i].replace(".","/").split("/");  
14:          
15:        DateTimeFormatter form = DateTimeFormatter.ofPattern("ddMMyyyy");  
16:        LocalDate datum = LocalDate.parse(textArray2[2], form);  
17:          
18:        Person p = new Person (textArray2[0], textArray2[1], textArray2[3], datum);  
19:          
20:        personList.add(p);  
21:      }  
22:        
23:      for (Object l : personList)  
24:        System.out.println(l.toString());  
25:    }  
26:  }  

Comments