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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:00:45+00:00 2026-06-05T13:00:45+00:00

The mac address string may be in format: 00:aa:bb:cc:dd:ee or 00aabbccddee I need a

  • 0

The mac address string may be in format:

00:aa:bb:cc:dd:ee

or

00aabbccddee

I need a good way to retrieve the 6 parts.

Here my code:

public class Mac
{
    public static void main(String[] args)
    {
        String mac = "00:aa:bb:cc:dd:ee"; /* 00aabbccddee */
        Scanner s = new Scanner(mac);
        s.useDelimiter(":?"); /* zero or one occurrence */                                                                                                                             
        String t = null;
        while ((t = s.next("[0-9a-f][0-9a-f]")) != null)
            System.out.println(t);
    }
}

It throws a exception:

Exception in thread "main" java.util.InputMismatchException
        at java.util.Scanner.throwFor(Scanner.java:840)
        at java.util.Scanner.next(Scanner.java:1461)
        at java.util.Scanner.next(Scanner.java:1394)
        at Mac.main(Mac.java:11)

What’s wrong with it?

  • 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-05T13:00:47+00:00Added an answer on June 5, 2026 at 1:00 pm
    public static String[] getMacAddressParts(String macAddress) {
        String[] parts = macAddress.split(":");
        if (parts.length == 0) {
            parts = new String[6];
            for (int i = 0; i < 6; i++) {
                parts[i] = macAddress.substring(i * 2, i * 2 + 1);
            }
        }
        return parts;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to retrieve system information like MAC Address, computer name, etc.
Hi i'm using this method for get the mac address public string GetMACAddress() {
How do I convert 6 bytes representing a MAC address into a string that
I want the user to enter a MAC address in the format : aa:bb:cc:dd:ee:ff
I have the following code that gets the MAC address of an interface: static
I want to convert a MAC address 00163e2fbab7 (stored as a string) to its
I have found this code to get a MAC address, but it returns a
I am using this code to find the MAC address of a machine. This
Possible Duplicates: Getting Machine’s MAC Address — Good Solution? How do I get the
I wrote the following code to get the MAC address: WifiManager wimanager = (WifiManager)

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.