Advertisement
Chiddix

insert

Sep 13th, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1.  
  2.     /** Inserts str into myLine at position index;
  3.      * no characters from myLine are overwritten.
  4.      * @param str the strng to be inserted
  5.      * @param index the position at which to insert str
  6.      *          Preconidtion: 0 <= index <= myLine.length()
  7.      */
  8.     public void insert(final String str, final int index) {
  9.         if (0 <= index && index <= myLine.length()) {
  10.             String begin = myLine.substring(0, index);
  11.             String end = myLine.substring(index);
  12.             myLine = begin + end;
  13.         }
  14.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement