0

I have a constructor like this :

Person (String name, int age, Calendar date_employment);

When i read this info from my file I get it as a String so how do I convert my String which contains my date into a Calendar type so I can pass it to my constructor?

Ivana
  • 1

1 Answers1

0

Why but my good lady or sir, it has already been covered! All you shall need to do is Google. Convert String to Calendar Object in Java

Jameson
  • 6,400
  • 6
  • 32
  • 53
  • Thank you, I did google it but it's not quite the answer i need. The converting part works fine until i need to pass it to my constructor. – Ivana Nov 01 '15 at 08:48
  • @Ivana is it throwing any error ? Post your code plz – Rahman Nov 01 '15 at 09:23
  • I'm doing this Calendar cal = Calendar.getInstance(); cal.set(year,month,date) ; I can't pass it to my constructor since it's not a Calendar type. I'm looking for a solution to this. – Ivana Nov 01 '15 at 09:31
  • I simplified it so the only thing i read from my file is the date : while ((line = flux_in.readLine()) != null) { aux = linie.split("-"); Calendar cal = Calendar.getInstance(); cal.set(Integer.parseInt(aux[0]),Integer.parseInt(aux[1]),Integer.parseInt(aux[2])); pers.add(new Person(cal)); // this is where I'm having trouble } – Ivana Nov 01 '15 at 09:40