Learn Java Programming - StringBuilder .insert() Method Tutorial

Опубликовано: 01 Октябрь 2015
на канале: Daniel Ross
2,082
15

In this tutorial I will talk about the insert() method. The insert method inserts the value of the parameter into the value of the current StringBuilder object at a specified position. There are a dozen overloaded versions of the insert() method that will allow you to pass in quite a few data types. For example, the insert(int offset, String str) method works like this:
StringBuilder sb = new StringBuilder("0123456789");
sb.insert(4, "ABC");
System.out.println(sb); // 0123ABC456789
The offset parameter is the index of the character sequence of the current StringBuilder object, the insertion will take place after the character specified by the offset. In this case 4 tells the method to insert the String parameter after the character located at the forth index. If you attempt to insert something at an invalid offset, the method will throw a StringIndexOutOfBoundsException.


На этой странице сайта вы можете посмотреть видео онлайн Learn Java Programming - StringBuilder .insert() Method Tutorial длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Daniel Ross 01 Октябрь 2015, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 2,082 раз и оно понравилось 15 зрителям. Приятного просмотра!