I'm trying to convert the below if
statement into a switch
expression.
public static int parseDays(String durationString) {
String[] parts = durationString.split(" ");
if (parts.length == 2) {
return unitValueCalculation(parts[1], parts[0]);
}
else if (parts.length == 1)
{
if (parts[0].equalsIgnoreCase("once")) return 1;
}
return 0;
}
This is what I've got:
public static int parseDays(String durationString) {
switch (durationString) {
case durationString.split(" ").length == 2 -> unitValueCalculation(parts[1], parts[2]);
}
I'm not sure what to do about the case statement, though.
Any ideas would be appreciated.