Lang.String

StringBuilder

?


?

原文:

public final class StringBuilder
extends Object
implements Serializable, CharSequence
A mutable sequence of characters. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.
The principal operations on a StringBuilder are the append and insert methods, which are overloaded so as to accept data of any type. Each effectively converts a given datum to a string and then appends or inserts the characters of that string to the string builder. The append method always adds these characters at the end of the builder; the insert method adds the characters at a specified point.
For example, if z refers to a string builder object whose current contents are "start", then the method call z.append("le") would cause the string builder to contain "startle", whereas z.insert(4, "le") would alter the string builder to contain "starlet".
In general, if sb refers to an instance of a StringBuilder, then sb.append(x) has the same effect as sb.insert(sb.length(), x).
Every string builder has a capacity. As long as the length of the character sequence contained in the string builder does not exceed the capacity, it is not necessary to allocate a new internal buffer. If the internal buffer overflows, it is automatically made larger.
Instances of StringBuilder are not safe for use by multiple threads. If such synchronization is required then it is recommended that StringBuffer be used.
Unless otherwise noted, passing a null argument to a constructor or method in this class will cause a NullPointerException to be thrown.

?

譯:

StringBuilder是在使用單線程時StringBuffer的替代品,StringBuilder沒有同步的權限,再涉及多線程時,還是要繼續使用StringBuffer。Method:方法主要有兩個:
StringBuilder sb = new StringBuild();
1.sb.append(str);
2.sb.insert(position,str);

tips:當參數為null時,會報空指針異常。

轉載于:https://www.cnblogs.com/kongieg/p/10628450.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/279793.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/279793.shtml
英文地址,請注明出處:http://en.pswp.cn/news/279793.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

牛客網暑期ACM多校訓練營(第二場)J farm (二維樹狀數組)

題目鏈接&#xff1a; https://www.nowcoder.com/acm/contest/140/J 思路&#xff1a; 都寫在代碼注釋里了&#xff0c;非常好懂。。 for_each函數可以去看一下&#xff0c;遍歷起vector數組比較方便&#xff0c;用for(int i 0;i < q[i].size();i)的話&#xff0c;是會有一…

微軟IE 9 Beta全程體驗圖集

微軟剛剛更新了IE 9 Beta的新頁面&#xff0c;此次發布的Beta版本一共有27個國家的語言&#xff0c;其中也包括了簡體中文和香港和臺灣的繁體中文版。 點擊此處進入下載頁面&#xff1a; http://windows.microsoft.com/zh-CN/internet-explorer/download/ie-9/worldwide IE9的熱…

.net core中Quartz的使用方法

我們在日常開發中&#xff0c;總會遇到這樣的需求&#xff1a;每隔一段時間&#xff0c;執行一次某個任務。固定某個時間執行任務&#xff0c;例如凌晨12點對當天的數據進行統計。每個月的第幾天&#xff0c;執行某個任務。Quartz.Net是根據Java的Quartz用C#改寫而來&#xff0…

AspectJ學習筆記

介紹 AspectJ是一個基于Java語言的AOP框架Spring2.0以后新增了對AspectJ切點表達支持AspectJ是AspectJ1.5新增功能&#xff0c;通過JDK5注解技術&#xff0c;允許Bean類中定義切面&#xff0c;新版本Spring框架&#xff0c;建議使用AspectJ方式來開發AOP主要用途&#xff1a;自…

windows10訪客_如何在Windows 10中創建訪客帳戶

windows10訪客If you find that your guests are asking fairly often to use your computer temporarily to check their email or look something up on the web, you don’t have to let them use your personal account or create a special account for each guest. 如果發…

C#使用 System.Net.Mail發送郵件功能

介紹System.Net.Mail命名空間是在.NET Framework中新增的&#xff0c;該命名空間提供了發送電子郵件的功能。通過對本章的學習&#xff0c;讀者可以輕松地使用.NET Framework提供的類庫來發送電子郵件。System.Net.Mail 命名空間包含用于將電子郵件發送到SMTP服務器的類&#x…

初識smarty

個人體會(不完全正確)&#xff1a;就是smarty就是為了更好的使得php/html結合做出來的一個框架。 , 轉載于:https://www.cnblogs.com/nul1/p/9357694.html

幾個有趣的算法題目

本文首發 http://svtter.cn最接近的數字 題目 一個K位的數N $$ (K\leq2000&#xff0c;N\leq10^{20}) $$ 找出一個比N大且最接近的數&#xff0c;這個數的每位之和與N相同&#xff0c;用代碼實現之。 例如&#xff1a;0050 所求書數字為0104&#xff1b;112 所求數為121&#x…

獲取一篇新聞的全部信息

給定一篇新聞的鏈接newsUrl&#xff0c;獲取該新聞的全部信息 標題、作者、發布單位、審核、來源 發布時間:轉換成datetime類型 點擊&#xff1a; newsUrlnewsId(使用正則表達式re)clickUrl(str.format(newsId))requests.get(clickUrl)newClick(用字符串處理&#xff0c;或正則…

上twitter_如何在Twitter上更改您的顯示名稱

上twitterUnlike Facebook, Twitter has never insisted people user their real names. In fact, there’s a long tradition of people changing their names to a joke or pun because it’s Christmas or Halloween, or just for no reason at all. 與Facebook不同&#xf…

技術走向管理一些思考(1)-性格特質和自我管理

技術走向管理一些思考-文件夾 1&#xff0c;管理需具備的性格特質 贊賞他人&#xff1a;以一種不以自我為中心的合作的方式和他人相處&#xff0c;能平靜和客觀地接受不同的人。放下自己的性格、喜好&#xff0c;去贊賞不同類型的人。不是通過個人友誼或者熟悉程度。而是通過某…

網橋

配置實現網橋 網橋&#xff1a;即橋接 把一套機器上的若干個網絡接口 “連接” 起來&#xff0c;其結果是&#xff0c;其中一個網口收到的報文會被復制給其他網口并發送出去。以使得網口之間的報文能夠互相轉發。網橋就是這樣一個設備&#xff0c;它有若干個網口&#xff0c;并…

Newtonsoft.Json Deserialize Type 或者 同類型 變量 反序列化

Newtonsoft.Json 經常再用 這樣的需求 還是很少用 場景 方法一&#xff1a;根據 Type 反序列化 int demo 0; string jsongString JsonConvert.SerializeObject(demo); int jsonDemo JsonConvert.DeserializeObject(jsongString, demo.GetType()); 方法二 根據 同類型變量 序…

raspberry pi_在月光下將Raspberry Pi變成蒸汽機

raspberry piValve’s Steam Machines aim to bring your Steam game library right into your living room (but at a rather steep premium). Today we’ll show you how to bring your Steam library (plus all your other computer games) to your living room for a fract…

文檔測試【轉載】

原文來自&#xff1a;51Testing軟件測試網采編 作者&#xff1a; 仙靈測試(sinablog) 原文鏈接&#xff1a;http://www.51testing.com/html/61/n-237961.html 1、文檔的種類 ● 聯機幫助文檔或用戶手冊 這是人們最容易想到的文檔。用戶手冊是隨軟件發布而印制的小冊子…

NOI2019省選模擬賽 第三場

傳送門 明明沒參加過卻因為點進去結果狂掉\(rating\)…… \(A\) 集合 如果我們記 \[f_k\sum_{i1}^nT^i{n-i\choose k}\] 那么答案顯然就是\(f_{k-1}\) 然后就可以開始推倒了 \[ \begin{aligned} f_k &\sum_{i1}^nT^i{n-i\choose k}\\ &\sum_{i1}^nT^i{n-i-1\choose k}\…

MySql數據庫出現 1396錯誤

1、安裝MySql數據庫后。創建新的用戶。有可能會出現 1396這個錯誤&#xff0c; 2、解決的辦法如下&#xff1a;假裝有你需要創建的這個用戶、先刪了。再創建。 3、這樣就可以解決用戶創建不成功的問題了。 轉載于:https://www.cnblogs.com/chifa/p/9362882.html

如何使用wink框架_如何解決Wink Hub的Z-Wave連接問題

如何使用wink框架Overall, the Wink hub works extremely well…but sometimes the devices you have connected to it can act a little wonky. Here are some things you can do in order to fix any connection issues with all of those Z-Wave sensors and devices connec…

Tomcat服務器啟動錯誤之Offending class: javax/servlet/Servlet.class

引子 最近在基于Wex5項目開發中&#xff0c;遇到使用過程中與Tomcat功能有關的錯誤提示&#xff0c; 如題所示。最終的解決方法就是刪除掉項目上與tomcat沖突的jar包。 org.apache.catalina.loader.WebappClassLoader validateJarFile ??: validateJarFile(/Users/zxzpc/…

面向對象進階(二)----------類的內置方法

一、isinstance(obj,cls)和issubclass(sub,super) 1. isinstance(obj,cls): 檢查是否obj是否是類 cls 的對象 class Player:passp Player()print(isinstance(p, Player))>>> Ture 2. issubclass(sub, super): 檢查sub類是否是 super 類的派生類 class Player:passcla…