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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:35:18+00:00 2026-06-14T21:35:18+00:00

I write a small java tool and a at the beginning I have to

  • 0

I write a small java tool and a at the beginning I have to parse a url. I would like to know, what you are thinking about my solution and if there is a better way?
Here are some examples:

aaa://username:password@server:port/dir/

aaa://server:port/dir/

aaa://server:port

Every kind of String is possible, if the user is not carefully. So it is possible, that my function get such a string

aaa://username:pass

too. But the string always starts witch aaa://.

Here is my code:

url = url.replaceFirst("aaa://", "");

String params[] = url.split("@");
if(params[0].compareTo("") != 0) {
    String paramsfst[] = params[0].split(":");
    if(params.length == 1) {
        if(paramsfst.length >= 1) {
            this.server = parsePort(paramsfst[0]);
            if(paramsfst.length == 2) {
                this.port = parsePort(paramsfst[1]);
            }
        }               
    } else {
        String paramssec[] = params[1].split(":");
        if(paramssec.length >= 1) {
            this.server = parsePort(paramssec[0]);
            if(paramssec.length == 2) {
                this.port = parsePort(paramssec[1]);
            }
        }
        if(paramsfst.length == 2) {
            this.username = paramsfst[0];
            this.password = paramsfst[1];   
        }
    }
    if(url.contains("/")) {
        this.path = url.substring(url.indexOf("/"), url.length() -1);   
    }

private String parsePort(String port) {
    int i = port.indexOf("/");
    if(i == -1) {
        return port;
    }
    return port.substring(0, i);
}

What do you think?

  • 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-14T21:35:19+00:00Added an answer on June 14, 2026 at 9:35 pm

    Have you looked at the URL class?

    See here for an example.

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

Sidebar

Related Questions

I have created a small game in Java and I would like to add
i have to write small java database application with several tables. With that i
i'm trying to write a small java class. I have an object called BigNumber.
I am new in java programming. I have write a small web program using
I am trying to write a small Java application that will let me run
I am getting ready to write lot of small experimental java programs as I
I am trying to write a small application using bouncycastle algorithm, from the BouncyCastleProvider.java
I have many small java programs running in crons in my server. I have
I have a developed two small Java applications - a vanilla Java app and
I want to write a small (5-6 table) desktop app in Java. I want

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.