title: How to parse String and send multiple values to constructor
body: <p>I am doing a class assignment where I have to parse a given string into different types of variables. The different variables are: <strong>Name, Surname, Date of Birth, City of Birth</strong>. After this is done, the variables needs to be sent to the constructor of the <strong>class Person</strong>. </p>
  
  <p>I am stuck with how to assign the three different values to a variable and then send it back to the constructor. I have tried declaring an array for each variable and then filling it with for loop with the values but then I ran into trouble finding a neat way of declaring its length plus I think I would need to convert the array back to strings in order to pass the values to the constructor and the resulting code would be messy. Is there a simpler way of doing this? </p>
  
  <p>I don't know if this will change anything in the code but after I passed the values to the constructor, I need to send that object to a List collection and use it to print the details about each person. </p>
  
  <p>Here is my current code: </p>
  
  <pre><code>    public static void main(String[] args) {
  
      // Given string to parse
      String text = "John.Davidson/05051988/Belgrade Michael.Barton/01011968/Krakov Ivan.Perkinson/23051986/Moscow";
  
      String[] parsArray = text.split("[ /.]+");
  
      // Results from parsing
      for (Object s: parsArray)
      {
          System.out.println(s);
      } 
  
      for (int i = 0; i&lt;parsArray.length; i+=4)
      {
          String firstName = parsArray[i];
          String lastName = parsArray[i+1];
          String birthPlace = parsArray[i+3];
          System.out.println("\nFirst name: " + firstName + "\nLast name: " + lastName + "\nCity of birth: " + birthPlace);
      }           
   }
   }
  </code></pre>
  
  <p><strong>Class Person</strong> and its constructor:</p>
  
  <pre><code>import java.time.LocalDate;
  
  public class Person {
  String name;
  String surname;
  LocalDate dob;
  String placeOfBirth;
  
  public Person(String name, String surname, LocalDate dob, String placeOfBirth)
  {
  this.name = name;
  this.surname = surname;
  this.dob = dob;
  this.placeOfBirth = placeOfBirth;
  }  
  }
  </code></pre>