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 convertResultToXML(int result) {
    return String.format(retString, result);
}

From source file:Main.java

public static String getLocalAbstractPath(File file) {
    return String.format("file://%s", file.getAbsoluteFile());
}

From source file:Main.java

public static String floatToDuration(String duration_in_float) {
    duration_in_float = String.format("%2.2f", Float.parseFloat(duration_in_float));
    String[] parts = duration_in_float.split("\\.");
    long minute = Long.parseLong(parts[0]);
    long seconds = (60 * Long.parseLong(parts[1])) / 100;
    return String.format("%02d:%02d", minute, seconds);
}

From source file:Main.java

public static UUID UUID16(final String s) {
    return UUID.fromString(String.format("0000%4s-0000-1000-8000-00805f9b34fb", s));
}

From source file:Main.java

public static String getBinaryString(byte[] bytes) {
    String result = "";
    for (byte b : bytes) {
        result = result + String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0');
    }/*from   w ww .  j a  v a  2  s.  co  m*/
    return result;
}

From source file:Main.java

public static String _byteArrayToHex(byte[] a) {
    StringBuilder sb = new StringBuilder();
    for (byte b : a)
        sb.append(String.format("%02x-", b & 0xff));
    sb.deleteCharAt(sb.length() - 1);//from  ww w . j ava2s  . c o m
    return sb.toString();
}

From source file:Main.java

private static String appendThrowable(String origin, Throwable tr) {
    String trMsg = tr == null ? "" : String.format(": %s", tr.toString());
    return String.format("%s%s", origin, trMsg);
}

From source file:Main.java

public static String convertToHex(int colorInt) {
    //noinspection HardCodedStringLiteral
    return String.format("#%06X", (0xFFFFFF & colorInt));
}

From source file:Main.java

public static String displayableSize(long bytes) {
    double kbytes = bytes / 1024.0;
    if (kbytes < 1000)
        return String.format("%.1f KB", kbytes);

    double mbytes = bytes / (1024.0 * 1024.0);
    if (mbytes < 1000)
        return String.format("%.1f MB", mbytes);

    double gbytes = bytes / (1024.0 * 1024.0 * 1024.0);
    return String.format("%.1f GB", gbytes);
}

From source file:Main.java

public static String bytes2Hex(byte[] bytes) {
    StringBuilder sb = new StringBuilder();
    for (byte b : bytes) {
        sb.append(String.format("%02X ", b));
    }// w  w  w.j  a  v  a 2s  . c  om
    return sb.toString();
}