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 6827471
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:16:10+00:00 2026-05-26T22:16:10+00:00

Why does the following code return the output below? I would expect that 2

  • 0

Why does the following code return the output below?
I would expect that 2 and 3 provide the same string splitting of 1.

    Log.d(TAG, " 1 ---------------------------");
String originalText = "hello. .hello1";

Pattern p = Pattern.compile("[a-zA-Z]+|\\s|\\W|\\d");
Matcher m = p.matcher(originalText);

 while (m.find()) { 
     Log.d(TAG, m.group(0)); 
 }
 Log.d(TAG, "2 --------------------------- " + originalText);

String [] scrollString = p.split(originalText);

int i;      
for (i=0; i<scrollString.length; i++)
    Log.d(TAG, scrollString[i]);

Log.d(TAG, "3 --------------------------- " + originalText);

scrollString = originalText.split("[a-zA-Z]+|\\s|\\W|\\d");


for (i=0; i<scrollString.length; i++)
    Log.d(TAG, scrollString[i]);

OUTPUT:

1 ---------------------------

hello

.

.

hello

1

2 ---------------------------

3 --------------------------- 
  • 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-26T22:16:11+00:00Added an answer on May 26, 2026 at 10:16 pm

    No. 1 will find the pattern and return that, whereas No. 2 and 3 will return the text in between the found pattern (which serves as the delimiter in those cases).

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

Sidebar

Related Questions

Why does following code has a correct output? int GGT has no return statement,
I'm using following code but cannot return data from MySQL. This is the output:
The following code does not produce the expected output. Why? wchar_t* wchar_t_printf_return(wchar_t* formatstring, ...){
Why does the following code give: #include<stdio.h> int voo() { printf (Some Code); return
I wrote the following code. It tries to create a storyboard that does the
What does malloc(0) return? Would the answer be same for realloc(malloc(0),0) ? #include<stdio.h> #include<malloc.h>
Does the following code render the using(...) function/purpose irrelevant? Would it cause a deficiency
The code pasted below does the following: creates an import hook creates a context
In the following code, why does 2 give output but not 3? The removechars
Why does the following code sometimes causes an Exception with the contents CLIPBRD_E_CANT_OPEN: Clipboard.SetText(str);

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.