public static String addToList(String newItem,String semicolonSepList,int maxItems){
  StringBuilder sb=new StringBuilder(newItem);
  String[] items=semicolonSepList.split(";");
  for (int i=0; i < items.length && i < maxItems; i++) {
    String port=items[i];
    if (port.equals(newItem)) {
      continue;
    }
    sb.append(";");
    sb.append(port);
  }
  return sb.toString();
}

public static String addToList ( String newItem , String semicolonSepList , int maxItems ) { StringBuilder sb = new StringBuilder ( newItem ) ; String [ ] items = semicolonSepList . split ( ";" ) ; for ( int i = 0 ; i < items . length && i < maxItems ; i ++ ) { String port = items [ i ] ; if ( port . equals ( newItem ) ) { continue ; } sb . append ( ";" ) ; sb . append ( port ) ; } return sb . toString ( ) ; }
add a new item to a semicolon separated list of strings .
