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

  • Home
  • SEARCH
  • 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 7723937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T04:34:10+00:00 2026-06-01T04:34:10+00:00

This is my string String s = asadsdas357902||190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC; I split it as

  • 0

This is my string

String s = "asadsdas357902||190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC";

I split it as

String a[] = s.split(s, i);

outputs: i=0

        |   |   1   9   0   |   |   R   U   E       R   A   C   H   E   L   L   E   |   |   S   T   |   |   |   L   E   S       C   È   D   R   E   S   |   J   7   T   1   J   9   |   Q   C   

First two indexes of array are empty nad then each index has one character.

When i=1, output is the whole original string

asadsdas357902||190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC

when i=2, output is

    ||190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC  

first index of array is empty and second contains the substring from first | symbol

when i=3, output is

        ||190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC

first two indexes are empty and last index has the same substring as for i=2

when i=4, output is

        |   |190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC   

first two indexes empty, next contains a pipe and last the rest

when i=5, output is

        |   |   190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC    

first two empty, next two pipe character and last the remaining.

as the i value increases, the output is

first two indexes empty
next all indexes except last contains one character each
last index contains the remaining string

My questions are

  1. Why it is not considering the first word before the first pipe symbol?
  2. Why it is making he first two indexes empty for every value of i except 1?
  3. The pattern is the same string here, so what is matched here and how the outputs come?

And another thing is if I replace the pipe symbol with any other symbol such as @ or ! or %, the output is

array length is 2 with both indexes has empty strings. this is for i>=2

for i=0

the array length is also 0

for i=1

the array length is 1 containing the whole string.

Is it taking the pipe symbol as a special regex symbol?

Any help appreciable.

  • 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-06-01T04:34:11+00:00Added an answer on June 1, 2026 at 4:34 am

    split method takes a regex as an input param. Now the regex in your case is
    asadsdas357902||190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC and the second parameter i is the number of times that split operation is applied. This is the explanation of your regex

                             // Match either the regular expression below (attempting the next alternative only if this one fails)
       "asadsdas357902" +       // Match the characters “asadsdas357902” literally
    "|" +                    // Or match regular expression number 2 below (attempting the next alternative only if this one fails)
       "|" +                    // Empty alternative effectively truncates the regex at this point because it will always find a zero-width match
                             // Or match regular expression number 3 below (attempting the next alternative only if this one fails)
       "190" +                  // Match the characters “190” literally
    "|" +                    // Or match regular expression number 4 below (attempting the next alternative only if this one fails)
       "|" +                    // Empty alternative effectively truncates the regex at this point because it will always find a zero-width match
                             // Or match regular expression number 5 below (attempting the next alternative only if this one fails)
       "RUE\\ RACHELLE" +        // Match the characters “RUE RACHELLE” literally
    "|" +                    // Or match regular expression number 6 below (attempting the next alternative only if this one fails)
       "|" +                    // Empty alternative effectively truncates the regex at this point because it will always find a zero-width match
                             // Or match regular expression number 7 below (attempting the next alternative only if this one fails)
       "ST" +                   // Match the characters “ST” literally
    "|" +                    // Or match regular expression number 8 below (attempting the next alternative only if this one fails)
       "|" +                    // Empty alternative effectively truncates the regex at this point because it will always find a zero-width match
                             // Or match regular expression number 9 below (attempting the next alternative only if this one fails)
       "|" +                    // Empty alternative effectively truncates the regex at this point because it will always find a zero-width match
                             // Or match regular expression number 10 below (attempting the next alternative only if this one fails)
       "LES\\ CÈDRES" +          // Match the characters “LES CÈDRES” literally
    "|" +                    // Or match regular expression number 11 below (attempting the next alternative only if this one fails)
       "J7T1J9" +               // Match the characters “J7T1J9” literally
    "|" +                    // Or match regular expression number 12 below (the entire match attempt fails if this one fails to match)
       "QC"                     // Match the characters “QC” literally
    

    So, your regex is effectively equivalent to asadsdas357902| in a way because the regex that comes after it is never tested. See the split method documentation here String#split

    This code would give you the same output

    private static void splitWithPipe() {
        String s = "asadsdas357902||190||RUE RACHELLE||ST|||LES CÈDRES|J7T1J9|QC";
        for (int i = 0; i < 10; i++) {
            String a[] = s.split("asadsdas357902|", i); 
            System.out.println(Arrays.toString(a));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider a string array shaped like this: string[] someName = new string[] { First,
split this String using function split. Here is my code: String data= data^data; String[]
How do i split this string. 6885558 8866887777 => [6, 88, 555, 8, 88,
I have this string: $array= 'orange, fruit, apple juice' I want to count the
I have this String str = a,pnp,a|pnp,lab2|pnp,a|pnp,lab2,utr,utr; String[] strings = str.split(|); This code won't
I have this string : 0=&task=rose&duration=1.25&user=15&1=&task=daisy&duration=0.75&user=25&2=&task=orchid&duration=1.15&user=7 I want this array structure : array( array(
So from this string: name[id] I need this: id I used str.split ('[]'), but
If I do this: string text = Hello, how are you?; string[] split =
From this string: /resources/pages/id/AirOceanFreight.xhtml I need to retrieve two sub-strings: the string after pages/
In this string: <0> <<1>> <2>> <3> <4> I want to match all instances

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.