最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

流讀取導(dǎo)致StringBuilder.toString()亂碼的問題及解決

 更新時(shí)間:2022年11月08日 09:47:06   作者:Andrew_Yuan  
這篇文章主要介紹了流讀取導(dǎo)致StringBuilder.toString()亂碼的問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

流讀取導(dǎo)致StringBuilder.toString()亂碼

亂碼問題

StringBuilder sb = new StringBuilder();
String s = new String(sb.toString().getBytes("ios8859-1"),"UTF-8");

順便回憶一下String, StringBuilder, StringBuffer直接的區(qū)別:

String對(duì)象每次追加字符串的時(shí)候都是創(chuàng)建了新的對(duì)象,消耗時(shí)間最長(zhǎng),性能最低,操作少量數(shù)據(jù)的時(shí)候可以用它;

StringBuilder和StringBuffer每次追加的都是同一個(gè)對(duì)象,消耗的時(shí)間短,性能優(yōu)良;

StringBuilder比StringBuffer更快一點(diǎn),因?yàn)镾tringBuffer是線程安全的,支持同步鎖,而StringBuilder是線程不安全的,所以在單線程的時(shí)候最好使用StringBuilder,多線程的時(shí)候則使用線程安全的StringBuffer。

Java StringBuilder toString()方法與示例

StringBuilder類的toString()方法 (StringBuilder Class toString() method)

toString() method is available in java.lang package.

toString()方法在java.lang包中可用。

toString() method is used to represent string denoted by this object (when we create a new string object so first it is created and instantiated to contain the data[set of characters] denoted by this object currently).

toString()方法用于表示此對(duì)象表示的字符串(當(dāng)我們創(chuàng)建一個(gè)新的字符串對(duì)象時(shí),首先創(chuàng)建并實(shí)例化它包含當(dāng)前由該對(duì)象表示的data [字符集])。

toString() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

toString()方法是一種非靜態(tài)方法,只能通過類對(duì)象訪問,如果嘗試使用類名稱訪問該方法,則會(huì)收到錯(cuò)誤消息。

toString() method does not throw an exception at the time of string representation.

toString()方法在字符串表示時(shí)不會(huì)引發(fā)異常。

Syntax:

句法:

public String toString();

Parameter(s):

參數(shù):

  • It does not accept any parameter.
  • 它不接受任何參數(shù)。

Return value:

返回值:

  • The return type of this method is String, it returns the string denotation of this set of characters represented by this object.
  • 此方法的返回類型為String ,它返回此對(duì)象表示的這組字符的字符串表示形式。

Example:

例:

// Java program to demonstrate the example?
// of String toString() method of StringBuilder?
?
public class ToString {
? ? public static void main(String[] args) {
?
? ? ? ? // Creating an StringBuilder object
? ? ? ? StringBuilder st_b = new StringBuilder("Java ");
?
? ? ? ? // By using append() method is to append the given string to?
? ? ? ? // st_b object
?
? ? ? ? st_b.append("World");
?
? ? ? ? // By using toString() method is to represent st_b
? ? ? ? // object to String
? ? ? ? System.out.println("st_b.toString() = " + st_b.toString());
? ? }
}

Output

輸出量

st_b.toString() = Java World

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

淮南市| 武冈市| 辉南县| 博客| 布拖县| 左云县| 泾阳县| 诸城市| 文登市| 巨鹿县| 连云港市| 洪江市| 榕江县| 讷河市| 册亨县| 林甸县| 岑溪市| 曲松县| 东丰县| 兴化市| 拜泉县| 塔城市| 兰溪市| 将乐县| 泗洪县| 兰坪| 宁晋县| 崇州市| 交口县| 永靖县| 贡觉县| 绥中县| 荥经县| 讷河市| 油尖旺区| 青海省| 葵青区| 海兴县| 灵丘县| 惠安县| 孟村|