0

I have a question regarding an assignment that I am doing on Java JFrame. I have a file filled with booking information (Booking number, name, surname, etc) and one of the options is date. I am then getting the information from the textfile, splitting everything according (position 0 = name, 1 = surname, etc) and putting them in their according arrayList (position 0 going in names arrayList, and so on).

public void loadBookings()
{
    String sContents = readTextFile("Bookings.txt");
    String [] sContents2 = sContents.split("\n");
    for(int i = 0; i<sContents2.length; i++)
    {
        String sContents3 = sContents2[i];
        String [] sContents4 = sContents3.split(",");

        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
            Date date1 = null;
            try{ 
                date1 = sdf.parse(sContents4[4]);
                GregorianCalendar cal = new GregorianCalendar();
                cal.setTime(date1);

                tableNumbers.add(Integer.parseInt(sContents4[0]));
                names.add(sContents4[1]);
                Surname.add(sContents4[2]);
                Contacts.add(sContents4[3]);
                dates.add(cal);
                quantity.add(Integer.parseInt(sContents4[5]));
                if(sContents4.length == 6)
                {
                    Comments.add("No Comment");
                }
                else{

                Comments.add(sContents4[6]);
                }

            }
            catch(Exception e)
            {}
    }  
    System.out.println(tableNumbers.toString());   
    System.out.println(names.toString());
    System.out.println(Surname.toString());
    System.out.println(Contacts.toString());
    System.out.println(dates.toString());
    System.out.println(quantity.toString());
    System.out.println(Comments.toString());      
}

Now, the code above runs normally with the names, Surname, dates, quantity and Comments being successfully inputted in their arrayList. The only problem I have having is that, instead of the dates, in the dates arrayList, I am seeing this error:

java.util.GregorianCalendar[time=1525903200000,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Europe/..... and so on.

Would be great to solve this problem. Thanks!

anothermh
  • 9,815
  • 3
  • 33
  • 52
johnny
  • 135
  • 1
  • 12
  • That's not an error, just the default string representation of a GregorianCalendar. If you don't like it you can use a formatter. – assylias Jan 16 '18 at 17:43
  • I just want them to be formatted as "dd/MM/yyyy" and I tried doing that but didn't manage. – johnny Jan 16 '18 at 17:46

0 Answers0