This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Compare Array with String Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Compare Array with String" Watch "Compare Array with String" New topic

Compare Array with String

nani aman
Ranch Hand

Joined: Sep 22, 2004
Posts: 33
hi, i have a string and an array of character.

String = "solve"
Array = {r,e,s,o,l,v,e}

how i can compare the string with the array to know that the string is in the array?

thank you. :roll:
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

I suggest that you have a look at the charAt method in java.lang.String class, and the String constructor that takes a character array as input.
Rohan Kayan
Ranch Hand

Joined: Sep 17, 2004
Posts: 123
You can create a new String object with char[] in its constructor and then you can use
public int compareTo(String anotherString)

SCWCD 1.4, SCJP 1.4
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: Compare Array with String
Similar Threads
Compare string to a String in array
Can I sort String arrays?
how to compare string Array with different string
Beta Search Criteria:
how compare array of string