The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

Re: Palindromes?

replaceAll works with a regular expression and in regexs '?', '(' and ')' are special characters with a specific meaning.

It seems you are not interested in regexs, so use replace(CharSequence target, CharSequence replacement) (Java 5+) instead of replaceAll(). Don't misunderstand the name, replace replaces all occurrences. Simply it doesn't use the concept of regexs.

But if you want to use regexs, you could also create a specific regex to match any of those single chars and replace them with empty string.

Ah, and this:
word = word.replaceAll(".","");

doesn't do what you want. It is correct but '.' in regex means "any character".

The regex [ ] is a "character class" and matches any of the characters contained. So [abc] matches 'a' OR 'b' OR 'c'. The good thing of character classes is that many of special characters lose their specific meaning. So outside [ ] the '.' means "any character" while [.] means "the point".

Re: Palindromes?

oh i see my teacehr never mentioned regex but showed us a way to remove all vowels. I didnt realize it worked for everything and could be changed.
this is what I learned string.replaceAll("[aeiou]", "");