Java Mac Address to String macToStr(byte[] mac)

Here you can find the source of macToStr(byte[] mac)

Description

Converts a MAC address to colon hexadecimal representation (e.g., "00:01:02:03:04:05").

License

Open Source License

Declaration

static public String macToStr(byte[] mac) 

Method Source Code

//package com.java2s;
/**/*  w  ww.ja  v a  2  s.c  o  m*/
 * NetUtil
 * Copyright (c) 2014 Frank Duerr
 *
 * NetUtil is part of SDN-MQ. This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    /**
     * Converts a MAC address to colon hexadecimal representation (e.g., "00:01:02:03:04:05").
     */
    static public String macToStr(byte[] mac) {
        StringBuilder strBuilder = new StringBuilder();

        for (int i = 0; i < mac.length; i++) {
            strBuilder.append(String.format("%02X", mac[i]));
            if (i < mac.length - 1) {
                strBuilder.append(":");
            }
        }
        return strBuilder.toString();
    }
}

Related

  1. macToBinary(String mac)
  2. macToString(byte[] mac)
  3. macToString(byte[] mac)
  4. macToString(final byte[] address)
  5. macToString(long macAddress)