CharSequence Interface in Java
By: Riktesh Srivastava
This article explains in detail about CharSequence interface in detail. The interface was recently introduced as a part of JDK 1.4. The article explains this interface in detail using a simple example.
In Java 1.4, both the String and the StringBuffer classes implements java.lang.CharSequence interface, which is a standard interface for querying the length of and extracting characters and subsequences from a readable sequence of characters. It can be explained with the help of example given below:
class A
{
public void dumpSeq(CharSequence cs)
{
System.out.println(\"length = \" + cs.length());
System.out.println(\"first char = \" + cs.charAt(0));
System.out.println(\"string = \" + cs);
int numChars = cs.length();
for(int i = 0; i < numChars; i++)
{
System.out.println(\"subsequence:\"+cs.subSequence(0,i+1));
}
}
}
class program
{
public static void main(String args[])
{
String s = \"test\";
A a=new A();
a.dumpSeq(s);
// StringBuffer
StringBuffer sb = new StringBuffer(\"ing\");
a.dumpSeq(sb);
}
}
Author URL: www.rikteshjava.blogspot.com
Archived Comments
1. Asking questions are really fastidious thing if you are not understanding something completely, but
View Tutorial By: geschenkefuermaenner.info at 2017-04-19 00:49:22
2. Debrakerne
View Tutorial By: Debrakerne at 2017-03-16 11:20:10
Comment on this tutorial
- Data Science
- Android
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Java program to get location meta data from an image
Program using concept of byte long short and int in java
Update contents of a file within a jar file
Tomcat and httpd configured in port 8080 and 80
Count number of vowels, consonants and digits in a String in Java
Student marks calculation program in Java
Calculate gross salary in Java
Calculate average sale of the week in Java
Vector in Java - Sample Program