我有下面的代码片段,需要一些帮助理解它的一些片段。新来散列码,需要帮助理解代码片段
String fileName = UUID.randomUUID().toString();
int hashcode = fileName.hashCode();
//I'm not sure why we are creating a mask with an int of 255
int mask = 255;
//Wny are we adding 255 to the hashcode?
int firstDir = hashcode & mask;
//What does it mean to have (hashcode >> 8) & mask? If I were to build a third
// tier would I use (hashcode >> 16) $ mask?
int secondDir = (hashcode >> 8) & mask;
StringBuilder sb = new StringBuilder(File.separator);
//I noticed when using this %02 it truncates the directory to 2 chars, does this
//just convert 3 digits to alpha numeric representing the same three digits?
sb.append(String.format("%02x", firstDir));
sb.append(File.separator);
sb.append(String.format("%02x", secondDir));
sb.append(File.separator);
最后,如果我想从两个目录生成一个文件名,我会只安装另一个字符串生成器,无文件分割符,或者它会更有效地先建字符串没有文件分隔符,然后分割字符串?
首先去看看'&'和'>>'运算符。 –
@SotiriosDelimanolis还有关于十六进制和格式化字符串! –
'&'(AND)是一个[按位运算符](http://en.wikipedia.org/wiki/Bitwise_operation) - 在尝试使用它们之前,先准备一些阅读和理解**。 –