Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
241 views
in Technique[技术] by (71.8m points)

dictionary - Data disappearing

I am trying to have a routine that holds a temporary map of data, then clears the original and puts the original data back into the map. The problem is the data is disappearing somewhere. ...

    public static void set( String dataGroup, Map<String,String> dataValues ) {
        if( dataGroup.equalsIgnoreCase( "TITLE" ) ) {
                System.out.println( "0101 roomTitles:" );
                for( String s : roomTitles.keySet() ) System.out.println( s + "=" + roomTitles.get( s ) );
                System.out.println( "0049 dataValues:" );
                for( String s : dataValues.keySet() ) System.out.println( s + "=" + dataValues.get( s ) );
                System.out.println( "roomTitles.clear()" );
            roomTitles.clear();
                System.out.println( "0057 roomTitles:" );
                for( String s : roomTitles.keySet() ) System.out.println( s + "=" + roomTitles.get( s ) );
                System.out.println( "0058 dataValues:" );
                for( String s : dataValues.keySet() ) System.out.println( s + "=" + dataValues.get( s ) );
            roomTitles = dataValues;
                System.out.println( "0052 roomTitles:" );
                for( String s : roomTitles.keySet() ) System.out.println( s + "=" + roomTitles.get( s ) );
                System.out.println();
        }
    }

I have indented the debugging lines I added trying to find the problem. The result was:

0101 roomTitles:
z(6--7s#;(=Unknown
0049 dataValues:
z(6--7s#;(=Unknown
        roomTitles.clear()
0057 roomTitles:
0058 dataValues:
0052 roomTitles:

The values in the map dataValues seems to disappear when I clear the map roomTitles. Can somebody tell me why?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...