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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:06:54+00:00 2026-06-10T12:06:54+00:00

I am attempting to parse the value of the elements in a List declared

  • 0

I am attempting to parse the value of the elements in a List declared as thus:

 List<String> uniqueList = new ArrayList<String>(dupMap.values());

The values are such as this:

a:1-2
b:3-5

but I want one ArrayList with the first number (i.e. 1, 3) and another with the second (i.e. 2, 5). I have this worked out… Sorta:

String delims= "\t"; String delim2= ":"; String delim3= "-";
String splits2[]; String splits3[]; String splits4[];
Map<String,String> dupMap = new TreeMap<String, String>();
List<String> uniqueList = new ArrayList<String>(dupMap.values());
ArrayList<String> parsed2 = new ArrayList<String>();
ArrayList<String> parsed3 = new ArrayList<String>();
ArrayList<String> parsed3two= new ArrayList<String>();
double uniques = uniqueList.size();
for(int a=0;a<uniques;a++){
    //this doesn't work like it would for an ArrayList
    splits2 = uniqueList.split(delim2) ;
    parsed2.add(splits2[1]);
    for(int q=0; q<splits2.length; q++){
        String change2 = splits2[q];
        if(change2.length()>2){
           splits3 = change2.split(delim3);
           parsed3.add(splits3[0]);
           String change3=splits3[q];
           if (change3.length()>2){
               splits4 = change3.split(delims);
               parsed3two.add(splits4[0]);
           }
        }
     }
  }

uniqueList.split does not work however and I don’t know if there is a similar function for List. Is there any suggestions?

  • 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-10T12:06:56+00:00Added an answer on June 10, 2026 at 12:06 pm

    If you know that all of your data is in the form [something]:[num]-[num], you can use a regular expression like this:

    Pattern p = Pattern.compile("^([^:]*):([^-]*)-([^-]*)$");
    
    // I assume this holds all the values:
    List<String> uniqueList = new ArrayList<String>(dupMap.values()); 
    
    for (String src : uniqueList) {
        Matcher m = p.matcher(src); 
        if( m.find() && m.groupCount() >= 3) {
            String firstValue = m.group(1); // value to left of :
            String secondValue = m.group(2); // value between : and -
            String thirdValue = m.group(3); // value after -
    
            // assign to arraylists here
        }
    }
    

    I didn’t actually put the code in to add to the specific ArrayLists because I couldn’t quite tell from your code which ArrayList was supposed to hold which value.

    Edit

    Per Code-Guru’s comment, an implementation using String.split() would go something like this:

    String pattern = "[:\\-]";
    
    // I assume this holds all the values:
    List<String> uniqueList = new ArrayList<String>(dupMap.values()); 
    
    for (String src : uniqueList) {
        String[] parts = src.split(pattern);
        if (parts.length == 3) {
            String firstValue = parts[1]; // value to left of :
            String secondValue = parts[2]; // value between : and -
            String thirdValue = parts[3]; // value after -
    
            // assign to arraylists here
        }
    }
    

    Both approaches are pretty much the same in terms of efficiency.

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

Sidebar

Related Questions

I am attempting to get unique values in a list of similar value distinguished
I am attempting to parse an xml string that has dates in there. The
I am attempting to parse a string in Perl with the format: Messages pushed
I am attempting to parse the following String into a DateTime object in c#:
I have a list of items in a hierarchy, and I'm attempting to parse
Attempting to recursively add XElements stepping through a category list. XElement dataResponse = new
I'm attempting to use regexp to parse a search string that from time to
I am attempting to parse (in Java) Wikimedia markup as found on Wikipedia. There
I am attempting to parse a XML file using Javascript and I'm running into
I am attempting to parse, not evaluate, rails ERB files in a Hpricot/Nokogiri type

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.