Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Convert string to CharSequence


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));
}
}

}



This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here

Share the post

Convert string to CharSequence

×

Subscribe to Java Tutorial : Blog To Learn Java Programming

Get updates delivered right to your inbox!

Thank you for your subscription

×