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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:18:20+00:00 2026-06-13T03:18:20+00:00

Here i have this type of String and i want to split this string

  • 0

Here i have this type of String and i want to split this string in to every elements and want to make one arraylist(integer) or one integer array for numbers.

I have String like this for a example : 123|00,124|01,125|00,126|01

I want to first seprate all elements in one list which contains

123|00
124|01
125|00
126|01

And after i want to make one integer array list or integer array which have only

123
124
125
126

Please any body can suggest me how can i do this

Thanks

Code:

            List<Integer> numberList = new ArrayList<Integer>();
        HashMap<Integer, Integer> statusMap = new HashMap<Integer, Integer>();
        for (String tripnumber : tripNumbers) {

            int number = Integer.parseInt(tripnumber.split("[|]")[0]);
            Logger.d(TAG, "Trip number in Status Message = "+number);

            int flag = Integer.parseInt(tripnumber.split("[|]")[1]);
            Logger.d(TAG, "TM flag = "+flag);

            if (number > 0) {
                statusMap.put(number, flag);
                numberList.add(number);
            }
        }
  • 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-13T03:18:21+00:00Added an answer on June 13, 2026 at 3:18 am
    String str = "123|00,124|01,125|00,126|01";
    
    // Split on `|` or `,` and then take every alternate element.
    String[] tokens = str.split("[|,]");
    
    List<Integer> intList = new ArrayList<Integer>();    
    for (int i = 0; i < tokens.length; i = i + 2) {
        intList.add(Integer.parseInt(tokens[i]));
    }
    

    UPDATE: –

    If you have inconsistent values separated by | and ,, then you need to split on them separately: –

    String str = "123|00,125|,126|01,|,";
    String[] tokens = str.split(",");
    Map<Integer, String> flagMap = new HashMap<Integer, String>();
    
        for (String token: tokens) {
            String[] arr = token.split("[|]");
    
            if (arr.length == 0) {
                continue;
            }
            if (arr[0].length() > 1) {
                if (arr.length == 2) {
                    flagMap.put(Integer.parseInt(arr[0]), arr[1]);
                } else {
                    flagMap.put(Integer.parseInt(arr[0]), "");
                }
            }
        }
    
        System.out.println(flagMap);
    

    OUTPUT: –

    {126=01, 125=, 123=00}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this following code, here CssClass is of the String type. <asp:Panel ID=Panel1
Here I have string like this 1322485986.672901000 , data type is string which represents
I have this code here, which is intended to allow any type of arguments:
I have this code down here. When format.js fires I want to serve to
I have this code right here, where the $friends variable is an array with
I have a string that represents a path to a directory. I want split
I have this complex type: <xsd:complexType name=Identifier> <xsd:sequence> <xsd:element name=Id type=xsd:string/> <xsd:element name=Version type=xsd:string/>
I have this XML here, and I want to set the max_width for the
Newbee question here - I have this method in the view controller m: -(void)
I am new to c# and I have this problem: I have here a

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.