Example usage for java.lang String hashCode

List of usage examples for java.lang String hashCode

Introduction

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

Prototype

public int hashCode() 

Source Link

Document

Returns a hash code for this string.

Usage

From source file:Main.java

public static void main(String[] args) {

    String str = "java2s.com";

    System.out.println("Hash code of string is = " + str.hashCode());
}

From source file:MainClass.java

public static void main(String[] args) {
    String s1 = "abc";
    String s2 = "abc";
    String s3 = "def";

    System.out.println("s1 hash code = " + s1.hashCode());
    System.out.println("s2 hash code = " + s2.hashCode());
    System.out.println("s3 hash code = " + s3.hashCode());
}

From source file:Main.java

public static String getFilenameForUrl(final String url) {

    return url.hashCode() + ".urlimage";
}

From source file:Main.java

private static String getRealFileName(String name) {
    return String.valueOf(name.hashCode());
}

From source file:Main.java

public static String getMusicLyricPath(String url) {
    return MUSIC_CACHE_DIR + "/" + url.hashCode() + ".lrc";
}

From source file:Main.java

public static BitmapDrawable getBackgroundPattern(String s) {
    return sTiledPlusStageDrawables[3 & s.hashCode()];
}

From source file:Main.java

public static long mixHash(String str) {
    long hash = str.hashCode();
    hash <<= 32;/*from ww  w  . ja va2  s. co m*/
    hash |= FNVHash1(str);
    return hash;
}

From source file:bridgempp.EndpointTranslator.java

public static int computeEndpointID(String string) {
    return string.hashCode();
}

From source file:Main.java

public static String generateHexFromString(String string) {
    return String.format("#ff" + "%06X", (0xFFFFFF & string.hashCode()));
}

From source file:Main.java

/**
 * calculates a color for a given name./*from  www .j a  v  a  2 s  .  c om*/
 *
 * @param name the name String
 * @return the calculated color
 */
public static int calculateColor(String name) {
    int hash = name.hashCode();
    int r = (hash & 0xFF0000) >> 16;
    int g = (hash & 0x00FF00) >> 8;
    int b = hash & 0x0000FF;

    //pastelize color
    r = (r + 127) / 2;
    g = (g + 127) / 2;
    b = (b + 127) / 2;

    return Color.rgb(r, g, b);
}