Example usage for java.lang String format

List of usage examples for java.lang String format

Introduction

In this page you can find the example usage for java.lang String format.

Prototype

public static String format(String format, Object... args) 

Source Link

Document

Returns a formatted string using the specified format string and arguments.

Usage

From source file:Main.java

public static String toRGBColor(int colorInt) {
    return String.format(TO_RGB, 0xFFFFFF & colorInt);
}

From source file:Main.java

public static String generatePercentile(int rank, int numTotalRuns) {
    double percentile = 100 - ((double) rank / numTotalRuns) * 100;
    return String.format("%.2f", percentile);
}

From source file:Main.java

public static String byteArrayToHex(byte[] a) {
    StringBuilder sb = new StringBuilder(a.length * 2);
    for (byte b : a)
        sb.append(String.format("%02x", b & 0xff));
    return sb.toString();
}

From source file:Main.java

public static int reduceColorOpacity(int color) {
    String colorHex = String.format("%06X", 0xFFFFFF & color);
    int resultColor = Color.parseColor("#55" + colorHex);
    return resultColor;
}

From source file:Main.java

public static final String buildSelectApdu(String aid) {
    StringBuilder sb = new StringBuilder();
    sb.append("00A40400");
    sb.append(String.format("%02X", aid.length() / 2));
    sb.append(aid);/* ww  w .  ja va 2  s. co m*/
    return sb.toString();
}

From source file:Main.java

public static String getArgId(String arg) {
    return String.format(ARG_ID_FORMAT, arg);
}

From source file:Main.java

public static String ByteArrayToString(byte[] arr) {
    StringBuffer sb = new StringBuffer();
    for (byte item : arr) {
        sb.append(String.format("%02X ", item & 0xFF));
    }//from   w ww .  j a v a2 s . com

    return "{ " + sb.toString() + "}";
}

From source file:Main.java

static void checkNotNull(Object o, String name) {
    if (o == null)
        throw new IllegalArgumentException(String.format("%s must be not null", name));
}

From source file:Main.java

public static String formatBytes(long bytes) {
    if (bytes < 1024) {
        return String.format("%d B", bytes);
    } else if (bytes < 1024 * 1024) {
        return String.format("%.2f kB", (float) bytes / 1024);
    } else if (bytes < 1024 * 1024 * 1024) {
        return String.format("%.2f MB", (float) bytes / 1024 / 1024);
    } else {/*from w  w w  . j a v  a  2 s .  c o m*/
        return String.format("%.2f GB", (float) bytes / 1024 / 1024 / 1024);
    }
}

From source file:Main.java

public static String formatSpeed(float speed) {
    if (speed < 1024) {
        return String.format("%.2f B/s", speed);
    } else if (speed < 1024 * 1024) {
        return String.format("%.2f kB/s", speed / 1024);
    } else if (speed < 1024 * 1024 * 1024) {
        return String.format("%.2f MB/s", speed / 1024 / 1024);
    } else {//from   www .  ja va 2  s  .c  o  m
        return String.format("%.2f GB/s", speed / 1024 / 1024 / 1024);
    }
}