When you see the definition of String class, it implements CharSequence interface.
public final class String implements java.io.Serializable, Comparable, CharSequence {
.....
.....
}
Since String class implements CharSequence interface, any string is a char sequence too.
Example
String str = "Hello World";
CharSequence cs = str;
App.java
package com.sample.app;
public class App {
public static void main(String args[]) {
String str = "Hello World";
CharSequence cs = str;
for (int i = 0; i System.out.println(cs.charAt(i));
}
}
}
Related Articles
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here