private static String mergeTextAndMnemonic(String text,final int mnemonic,final int mnemonicIndex){
  if (text == null) {
    text="";
  }
  final int index;
  if (mnemonicIndex >= 0 && mnemonicIndex < text.length() && Character.toUpperCase(text.charAt(mnemonicIndex)) == mnemonic) {
    index=mnemonicIndex;
  }
 else {
    index=-1;
  }
  final StringBuffer buffer=new StringBuffer(text);
  if (index != -1) {
    buffer.insert(index,'&');
    for (int i=buffer.length() - 1; i >= 0; i--) {
      if (buffer.charAt(i) == '&' && i != index) {
        buffer.insert(i,'&');
      }
    }
  }
  return buffer.toString();
}

private static String mergeTextAndMnemonic ( String text , final int mnemonic , final int mnemonicIndex ) { if ( text == null ) { text = "" ; } final int index ; if ( mnemonicIndex >= 0 && mnemonicIndex < text . length ( ) && Character . toUpperCase ( text . charAt ( mnemonicIndex ) ) == mnemonic ) { index = mnemonicIndex ; } else { index = - 1 ; } final StringBuffer buffer = new StringBuffer ( text ) ; if ( index != - 1 ) { buffer . insert ( index , '&' ) ; for ( int i = buffer . length ( ) - 1 ; i >= 0 ; i -- ) { if ( buffer . charAt ( i ) == '&' && i != index ) { buffer . insert ( i , '&' ) ; } } } return buffer . toString ( ) ; }
utility method which merge together text and mnemonic at some position
