You could probably use a Conditional Operator aka, the ternary (?:) operator where (a ? b : c) says if a is true, evaluate b, else evaluate c. and do it like this.
String.join("-", date.getYear(), date.getMonth(),
date.getDay().isEmpty() ? "c" : date.getDay());
Here's an example using a record as a simple Date class.
record Date(String getYear, String getMonth, String getDay) {
Date date1 = new Date("2002", "10", "30");
Date date2 = new Date("2002", "10", "");
System.out.println(String.join("-", date1.getYear(),
date1.getMonth(),
date1.getDay().isEmpty() ? "c" : date1.getDay()));
System.out.println(String.join("-", date2.getYear(),
date2.getMonth(),
date2.getDay().isEmpty() ? "c" : date2.getDay()));
prints
2002-10-30
2002-10-c
But you may want to provide more information including your use case as more constructive help could result. And make certain you aren't using the old Date class but those classes in the java.time package.
String.join("-", date.getYear(), date.getMonth(), date.getDay().length() > 0 ? date.getDay() : "c")?the date value can be empty, so I would get "2000-03-"- What do you mean by saying "date value can be empty"? What is the type ofdate?java.timepackage, likeLocalDate.