Java中CharArrayWriter类的toString()方法将给定的输入数据转换为字符串。
用法:
public char[] toCharArray()
参数:此方法不接受任何参数。
返回值:此方法返回输入数据的副本。
以下示例程序旨在说明上述方法:
示例1:
// Java program to illustrate the
// above mentioned method
import java.io.*;
public class GFG {
public static void main(String[] args)
throws IOException
{
// Initializing String Witer
CharArrayWriter geek_writer1
= new CharArrayWriter();
CharSequence char_sq1 = "geeks for + ";
CharSequence char_sq2 = "geeks";
// Use of append(CharSequence char_sq)
geek_writer1.append(char_sq1);
geek_writer1.append(char_sq2);
// Convert it into string and print
System.out.println("String : "
+ geek_writer1.toString());
}
}
输出:
String : geeks for + geeks
示例2:
// Java program to illustrate the
// above mentioned method
import java.io.*;
public class GFG {
public static void main(String[] args)
throws IOException
{
// Initializing String Witer
CharArrayWriter geek_writer1
= new CharArrayWriter();
CharSequence char_sq1 = "Gopal ";
CharSequence char_sq2 = "Dave";
// Use of append(CharSequence char_sq)
geek_writer1.append(char_sq1);
geek_writer1.append(char_sq2);
// Convert it into string and print
System.out.println("String : "
+ geek_writer1.toString());
}
}
输出:
String : Gopal Dave
参考: https://docs.oracle.com/javase/10/docs/api/java/io/CharArrayWriter.html#toString()
相关用法
- Java CharArrayWriter flush()用法及代码示例
- Java CharArrayWriter close()用法及代码示例
- Java CharArrayWriter size()用法及代码示例
- Java CharArrayWriter reset()用法及代码示例
- Java CharArrayWriter toCharArray()用法及代码示例
- Java LongAccumulator toString()用法及代码示例
- Java Scanner toString()用法及代码示例
- Java BigDecimal toString()用法及代码示例
- Java AtomicLong toString()用法及代码示例
- Java StringBuffer toString()用法及代码示例
- Java Modifiers toString()用法及代码示例
- Java Writer toString()用法及代码示例
- Java LinkedTransferQueue toString()用法及代码示例
- Java Pattern toString()用法及代码示例
- Java Calendar toString()用法及代码示例
注:本文由纯净天空筛选整理自gopaldave大神的英文原创作品 CharArrayWriter toString() method in Java with examples。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。