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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:52:27+00:00 2026-05-13T11:52:27+00:00

I have an arraylist that contains urls in the form similar to : stackoverflow.com/questions/ask/hello

  • 0

I have an arraylist that contains urls in the form similar to :

stackoverflow.com/questions/ask/hello
stackoverflow.com/questions/ask
stackoverflow.com/questions
stackoverflow.com/

If I only wanted to keep the first one and remove the rest, how would I go about doing that since technically they are not duplicates.
I thought of using substring manipulation but not to sure how to implement that.any ideas appreciated.

  • 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-13T11:52:27+00:00Added an answer on May 13, 2026 at 11:52 am

    Assuming I understand the question correctly, you can accomplish this by looping through your ArrayList, building a list of found domains, and simultaneously outputting a new list only when the found domain is not already a member of that first list.

    Or, you could build a dictionary of domain to url by iterating through the ArrayList in reverse. Since a dictionary can only have one value per key, the URLs will overwrite themselves in the dictionary and you will only have one URL per domain. Since you iterated in reverse, you will be left with a dictionary containing the first match in the ArrayList. You could then use LINQ to grab just the values (e.g. MyDictionary.Select(elem => elem.Value)).

    An example implementation of the second way I mentioned (in C#, you can convert it) is:

    Dictionary<string, string> MyDictionary = new Dictionary<string, string>();
    foreach(string Url in MyArrayList.Reverse())
        MyDictionary[Url.Split("/")[0]] = Url;
    

    There are dozens of ways you could accomplish this task. These are just two examples.

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

Sidebar

Related Questions

I have an arraylist that contains items called Room. Each Room has a roomtype
I have an arraylist (eg: h1) contain some urls. eg: http://www.google.com,http://www.yahoo.com,http://www.xyz.com ,..... How can
I have an ArrayList that contains, [0] = 1 [1] = 10 [2] =
I have an ArrayList that contains Strings and also contains other ArrayLists which may
I have an ArrayList of contacts that contains a phone number and a status
I have an ArrayList<String> that I'd like to return a copy of. ArrayList has
In Java, say you have a class that wraps an ArrayList (or any collection)
I have two arraylists that contains links in one and the root url in
I have an ArrayList containing Objects that have a date value. Now I want
I have an array list that contains Quote objects. I want to be able

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.