字符串对象的哈希码 [英] hash code for string objects

查看:112
本文介绍了字符串对象的哈希码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我是java编程的新手,我想创建多个字符串,因为编写了代码.This.why会为两个字符串对象生成相同的哈希代码。

Hi I am new to java programming,i want to create to multiple number of strings, for that written the code Below.why does it generating same hash code for both string objects.

   class SingletonClass {
            public static String mystring="this"; 
        }
        public class SingletonObjectDemo {
            public static void main(String args[]) {
                String str = SingletonClass.mystring;
                String str2 = SingletonClass.mystring;
                System.out.println("String str  "+str.hashCode());
                System.out.println("String str1  "+str2.hashCode());
                    }
        }


推荐答案

这是为两个字符串对象生成相同的哈希码...因为它们是同一个对象。

It's generating the same hash code for both string objects...because they're the same object.

这篇关于字符串对象的哈希码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆