StringWriter write(char[], int, int) method in Java with Examples Last Updated : 11 Jul, 2025 Suggest changes Share Like Article Like Report The write(char[], int, int) method of StringWriter Class in Java is used to write a specified portion of the specified character array on the writer. This character array is taken as a parameter. The starting index and length of characters to be written are also taken as parameters. Syntax: public void write(char[] charArray, int startingIndex, int lengthOfCharArray) Parameters: This method accepts three mandatory parameters: charArray which is the character array to be written in the writer. startingIndex which is the starting index from which the portion of character is to taken. lengthOfCharArray which is the length of characters to be written on the writer. Return Value: This method does not returns any value. Below programs illustrates the working of write(char[], int, int) method: Program 1: Java // Java program to demonstrate // StringWriter write(char[], int, int) method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Get the character array // to be written in the writer char[] charArray = { 65, 66, 67 }; // Get the starting index int startingIndex = 0; // Get the length of char int lengthOfCharArray = 1; // Write the portion of the charArray // to this writer using write() method // This will put the charArray in the writer // till it is printed on the console writer.write(charArray, startingIndex, lengthOfCharArray); System.out.println(writer.toString()); } catch (Exception e) { System.out.println(e); } } } Output: A Program 2: Java // Java program to demonstrate // StringWriter write(char[], int, int) method import java.io.*; class GFG { public static void main(String[] args) { try { // Create a StringWriter instance StringWriter writer = new StringWriter(); // Get the character array // to be written in the writer char[] charArray = { 97, 98, 99 }; // Get the starting index int startingIndex = 2; // Get the length of char int lengthOfCharArray = 1; // Write the portion of the charArray // to this writer using write() method // This will put the charArray in the writer // till it is printed on the console writer.write(charArray, startingIndex, lengthOfCharArray); System.out.println(writer.toString()); } catch (Exception e) { System.out.println(e); } } } Output: c Create Quiz C code_r Follow 0 Article Tags : Java Java-Functions Java-IO package Java-StringWriter Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References7 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers1 min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read My Profile ${profileImgHtml} My Profile Edit Profile My Courses Join Community Transactions Logout Like