You might want to familiarise yourself with the
String class:
String (Java Platform SE 7 ). The
String class does not have a
getChar method. Instead it has a "
getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)" method, which "copies characters from this string into the destination character array." Using this method will complicate things unnecessarily.
The method to use is "
charAt(int index)", which, incidentally, is one of the methods you previously used in post #1. The idea is to add each of the characters in a string into a set, and so you'd want to do something like:
for (int i = 0; i < sentence.length(); i++) {
checker.add(sentence.charAt(i));
}
The
charAt method returns a primitive
char type, whereas
checker is declared as a
Set<String> (i.e., a
Set of
String elements.) Therefore the next thing to do is to change
checker so that it is a
Set<Character> (a
Set of
Characters, where
Character "
wraps a value of the primitive type
char in an object"), and make the corresponding change for
HashSet as well.
Note that apart from arrays, Java's data structures (e.g.,
Set) generally can only store objects (e.g.,
Character) and not primitives (e.g.,
char). However "
checker.add(sentence.charAt(i));" will work. This is possible through
autoboxing - the "automatic conversion that the Java compiler makes between the primitive types and their corresponding object wrapper classes."