Java don't execute some lines of my code when I use Calendary library.
I'm trying to get the date of monday before 1 of actual month.
//Today is Tuesday, 2 January of 2019 (29/01/2019)
Calendar cp1 = GregorianCalendar.getInstance();
cp1.set(Calendar.DAY_OF_MONTH, 1); //THIS LINE DON'T WORKS
cp1.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
SimpleDateFormat sdf=new SimpleDateFormat ("dd/MM/yyyy");
System.out.println(sdf.format (cp1.getTime()));
// return 28/01/2019 instead of 31/12/2018.
IF I ADD System.out.println(cp1)
after line 2 java don't jump line 2 and works well.
//Today is Tuesday, 2 January of 2019 (29/01/2019)
Calendar cp1 = GregorianCalendar.getInstance();
cp1.set(Calendar.DAY_OF_MONTH, 1); //THIS LINE WORKS NOW
System.out.println (cp1.getTime());
cp1.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
SimpleDateFormat sdf=new SimpleDateFormat ("dd/MM/yyyy");
System.out.println(sdf.format (cp1.getTime()));
//return 31/12/2018 that is the correct date.
//Why java didn't execute 2nd line in my first code? Is a java bug?
Expected result "31/12/2018". Actual result "28/01/2019".