Java Program to Illustrate Use of getChar() and split() Method

This is a Java Program to Illustrate Use of getChar() and split() Method.

Here we divide the given string into array of strings depending upon the positions of blank spaces. Also we use getChar() method to get characters from given given string.

Here is the source code of the Java Program to Illustrate Use of getChar() and split() Method. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.

  1. public class Split_getChar
  2. {
  3.     public static void main(String args[]) 
  4.     {
  5.         String[] a;
  6.         String b = "Sanfoundary 1000 Java Programs";
  7.         a = b.split(" ");
  8.         for (int i = 0; i < a.length; i++) 
  9.         {
  10.             System.out.println(a[i]);
  11.         }
  12.         System.out.println("Using getChar() method:");
  13.         char c[]=new char[11];
  14.         b.getChars(0, 11, c, 0);
  15.         for(int i=0;i<11;i++)
  16.         {
  17.             System.out.print(c[i]);
  18.         }
  19.     }
  20. }

Output:

$ javac Split_getChar.java
$ java Split_getChar
 
Sanfoundary
1000
Java
Programs
Usin getChar() method:
Sanfoundary

Sanfoundry Global Education & Learning Series – 1000 Java Programs.

advertisement
advertisement

Here’s the list of Best Books in Java Programming, Data Structures and Algorithms.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.