Java getChars() method

    getChars() method

    This method will allow you to copy the string content into a specified char array. There will be four arguments that will be passed to this method.

    Method implementation-

    void getChars(char dst[], int dstBegin) {  
    
            System.arraycopy(value, 0, dst, dstBegin, value.length);  
    
        } 

    Syntax-

    public void getChars(int srcBeginIndex, int srcEndIndex, char[] destination, int dstBeginIndex)  

    Example-

    public class Simple{  
    
       public static void main(String[] args)
         {      
    
           String s1 = "Welcome Java";          
    
           char[] ch = new char[10];  
    
           try{  
    
             s1.getChars(6, 9, ch, 0);  
    
             System.out.println(ch);  
    
           }
           catch(Exception exp){System.out.println(exp);}        
        }
    }  

    Output-

    Java getChars method