I want to skip first occurrence if no of occurrence more than 4. For now I will get max of 5 number underscore occurrence. I need to produce the output A_B, C, D, E, F and I did using below code. I want better solution. Please check and let me know. Thanks in advance.
String key = "A_B_C_D_E_F";
int occurance = StringUtils.countOccurrencesOf(key, "_");
System.out.println(occurance);
String[] keyValues = null;
if(occurance == 5){
key = key.replaceFirst("_", "-");
keyValues = StringUtils.tokenizeToStringArray(key, "_");
keyValues[0] = replaceOnce(keyValues[0], "-", "_");
}else{
keyValues = StringUtils.tokenizeToStringArray(key, "_");
}
for(String keyValue : keyValues){
System.out.println(keyValue);
}