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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:35:25+00:00 2026-06-06T15:35:25+00:00

I have a series of strings (URLs) in different forms as: http://domain name.anything/anypath https://dmain

  • 0

I have a series of strings (URLs) in different forms as:

  1. http://domain name.anything/anypath
  2. https://dmain name.anything/anypath
  3. http://www.domain name.anything/anypath
  4. https://www.dmain name.anything/anypath

These strings are saved in CSV file. I need to parse every URL in order to get the domain name only, domain name.anything. i.e, the part after the first . and before the first /.

I separated the strings using split method, then converted each string to a URL, then used the toAuthority function to get the domain name only. The problem is that, toAuthority and toHost are doing the same job for me, they include the www. that I don’t want. Though, in the tutorial from Oracle, it seems that toAuthority supposed to return the domain name without www..

How can I extract the domain name part only without the www. of the URL ??

  • 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-06T15:35:27+00:00Added an answer on June 6, 2026 at 3:35 pm

    What is the difference between the getHost and getAuthority methods in the URL class?

    To really understand this, you should read URI specification – RFC 2396.

    The short answer is that the authority component consists of the host component together with an optional port number, username and password … depending on the URL scheme that is used.


    How can I extract the domain name part only without the “www.” of the URL ??

    You call getHost(), test if it starts with the string "www." and if it does you remove it.

    But before you start doing things like that, you need to understand that removing the “www.” may give you a URL that doesn’t work, or that resolves to a document or service that is different to the one the the original URL resolves to. It is a bad idea to gratuitously tidy up URLs … unless you have detailed knowledge of how the sites in question are organized.

    The convention that “foo.com” and “www.foo.com” are the same place is just a convention, and a lot of sites don’t implement it. Removing “www.” would be a bad idea because it is liable to turn resolvable URLs into URLs that don’t resolve.

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

Sidebar

Related Questions

I have a series of strings and their replacements separated by spaces: a123 b312
Sorry if the title doesn't make sense. Basically I have a series of strings
Let's say I have strings like this: PH&N 2015 LifeTime Series D PH&N 2020
I have a series of very complex XML files. I need to access these
I have a series of MongoDB records like: {name:Bob, gpa:4} {name:Sarah, gpa:3} I will
I have a series of date strings in the format: 30-05-2001 string date1 =
I have a series of application properties which all have different types. The types
I have two arrays containing different keys and values. However, some keys store strings
I have a series of URLs that look like /Catalog/Ajax/Update/{ViewToUpdate}?var1=a&var2=b&var3=c Currently I've setup several
I have a series of strings that come in, that are essentially dollar values,

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.