0

How do I save WEEK_OF_YEAR as a variable

I'm trying to save WEEK_OF_YEAR so that I can compare it against other WEEK_OF_YEAR, and I tried using Integer.toString(cl.WEEK_OF_YEAR) = currentweek where current week is the string and cl is the calender name. I get an error unexpected type required: variable found: value I tried defining cl.WEEK_OF_YEAR=intcurrentweek where intcurrentweek is an integer, but it still doesn't work. After checking online WEEK_OF_YEAR should be an integer, so I'm not sure why I can't save it as a string or integer. what should I do?

17th Apr 2020, 1:48 PM
Yu Hang Ng
Yu Hang Ng - avatar
1 Answer
0
cl.WEEK_OF_YEAR is just ID of this property, and is final, you can't change it // cl.WEEK_OF_YEAR = intCurrentWeek; //error notice: == compare; = assign this is assign value to value, it's wrong : // Integer.toString(cl.WEEK_OF_YEAR) = currentWeek; //error -------------- Calendar cl = Calendar.getInstance(); String strCurrentWeek = "16"; int intCurrentWeek = cl.get(Calendar.WEEK_OF_YEAR); // use .equals() to safe compare Strings boolean res = Integer.toString(intCurrentWeek) .equals(strCurrentWeek); System.out.println(res);
17th Apr 2020, 11:18 PM
zemiak