How to use the boolean contains(Charsequence s) method in Java? -



How to use the boolean contains(Charsequence s) method in Java? -

how pass desired sequence ('admin') contains method?

class containstest { public static void main( string [] args) { system.out.println("enter string"); scanner s = new scanner (system.in); string s = s.next(); char = 'admin' ; boolean flag; flag = s.contains(charsequence a); if (flag == true) { system.out.println("admin mode"); } else { system.out.println("customermode"); } } }

problem code in line

char = 'admin' ;

you cannot declare char that. there multiple characters in admin need utilize either character array or string store admin.

by using char array char[] = {'a', 'd', 'm', 'i', 'n'};

i don't think need utilize character array in problem, need utilize string.

by using string: string = "admin";

after declaring string can phone call contains method :

flag = s.contains(a);

note char in java written in ' ' , string written in " ". java documentation strings : https://docs.oracle.com/javase/7/docs/api/java/lang/string.html

java

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -