String fileId = "CPP420.A2_2012072416244467745";
String reg1 = "CPP350";
String reg2 = "CPP420.A1";
String reg3 = "CPP420.A2";
String country = "";
if(fileId.startsWith(reg1)) {
country = "CA";
} else if(fileId.startsWith(reg2)) {
country = "US";
} else if(fileId.startsWith(reg3)) {
country = "FR";
} else {
System.out.println("Error invalid file");
}
OR
String country = fileId.startsWith(reg1) ? "CA" : "";
country = fileId.startsWith(reg2) ? "US" : "";
country = fileId.startsWith(reg3) ? "FR" : "";
if("".equals(country)) {
System.out.println("No country found");
}