Use this method:
//********** MODIFIED *************//
public static void getSentence(String line) {
String text[] = line.split(",");
String res = "";
for (int i = 0; i < text.length; i++) {
String word = text[i].trim();
if (word.matches("[a-zA-Z]+[0-9]*")){
if (!"".equals(res))
res = res + "%";
res = res + word;
}
}
if ("".equals(res))
res = "%";
else
res = "%" + res + "%";
System.out.println(res);
}
...
this.getSentence("New, 12-Mar-14, 123, dat_123, Data123");
this.getSentence("12-mar-14, 21, 123_4, Value123, USER, 12/2/13");
Output:
%New%Data123%
%Value123%USER%