Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7678337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T17:37:24+00:00 2026-05-31T17:37:24+00:00

I did a little research with the String’s contains and replaceAll methods. char c

  • 0

I did a little research with the String’s contains and replaceAll methods.

char c = '*';

String str = "1220"+c+""+c+""+c+""+c+""+c+"23";
System.out.println(str.contains(c+""));
System.out.println(str.contains("["+c+"]"));
System.out.println(str.contains("\\"+c));


System.out.println(str.replaceAll("["+c+"]", "X"));
System.out.println(str.replaceAll("\\"+c, "X"));
System.out.println(str.replaceAll(c+"", "X"));

Results :
When c = ‘*’ or ‘^’ or ‘+’

true
false
false
1220XXXXX23
1220XXXXX23
java.util.regex.PatternSyntaxException

When c = ‘#’ or ‘~’ or ‘%’ or ‘<‘ or ‘>’ or ‘=’ or ‘&’ or ‘@’ or ‘-‘ or ‘!’

true
false
false
1220XXXXX23
1220XXXXX23
1220XXXXX23

When c = ‘$’

true
false
false
1220XXXXX23
1220XXXXX23
1220$$$$$23X

when c = ‘|’

true
false
false
1220XXXXX23
1220XXXXX23
X1X2X2X0X|X|X|X|X|X2X3X

I am wondering about what is the theory / rule behind this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T17:37:25+00:00Added an answer on May 31, 2026 at 5:37 pm

    The argument of contains and the first argument of replaceAll are interpreted differently: the former is just a character sequence, while the later is a regular expression. Since * is a meta-character of the Java’s regexp language that cannot appear unescaped on its own (it must follow an expression being repeated zero or more times in the match), it is treated differently by the two methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I did a little research and I didn't find a way, anyone know? c#
I did a little research, and an unsure if I should be using the
I have been noticing __construct a lot with classes. I did a little reading
Why did some processor manifacturers decide to use Little endian Big endian Middle endian
I did a little GP (note:very little) work in college and have been playing
I did some research on Google but I couldn't find any HTML5 browser for
I just did a little experiment: public abstract class MyClass { private static int
well i did my research and seen a lot of posts about this but
I did some research and looking around and it seems the way to do
I need to sign XML SOAP requests in Android application. I did a little

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.