How to use CharSequence

4.4k Views Asked by At

Hey i'm having some trouble understanding CharSequence.
I think this will be the perfect method to help with my hw but im having trouble understanding how to use it.
How do i make the sequence < /p> comes up.

This is what i have so far:

String s = "</p>";
char c;

while(reads.hasNext()){
c = reads.next();
    s = "" + c;
    if (inputPath.contains(?)) {
    // how do i make it return true if it contains < /p>
    }
}
2

There are 2 best solutions below

0
On

Assuming you are talking about java.lang.CharSequence, it is an interface, and is the parent for String, StringBuilder, and StringBuffer (and some other things).

It looks like you are more looking to see if the input you have so fat has, or contains a given string (</p>). To do that you could make use of the Pattern class or the String.equals or String.indexOf method (or the StringBuilder version).

0
On

You can test that one String contains another using indexOf():

if (inputPath.indexOf("< /p>") != -1) {
    // inputPath contains "< /p>" somewhere in it
}