[JAVA] About the matter that I was addicted to how to use hashmap

Introduction

I, ~ March 2013 Graduated from the Faculty of Arts and Sciences ~ April 2018 Infrastructure SIer # Linux or Azure May 2018-WEB engineer # I wanted to be able to develop Following the transition, I am studying Java in a highly acclaimed business.

If you can learn how to develop I would like to do my best so that I can acquire full-stack skills.

Please note that there may be many descriptions for beginners.

What I wanted to do

Process the information obtained by crawling and The process of inserting into multiple tables

① Create a common map and enter information (2) Create a Map for A table, insert the Map of (1), process the Map for A table, and insert it into the A table. ③ Create a map for B table, insert the map of ①, process the map for B table and insert it into the B table.

I wanted to do that

What I did (failure)

Execute the following method

public void putMain()  {
        Map<String, Object> insertData = new HashMap<>();
        insertData.put("aaa","aaa");
        insertData.put("bbb","bbb");
        insertData.put("ccc","ccc");
        putA(insertData);
        putB(insertData);
}
public void putA(Map<String, Object> insertData)  {
        Map<String, Object> aData = new HashMap<>();
        aData = insertData;
        aData.remove("bbb");
        insert(aData);
}
public void putB(Map<String, Object> insertData)  {
        Map<String, Object> bData = new HashMap<>();
        bData = insertData;
        bData.remove("aaa");
        insert(bData);
}
Expected result
insertData aData bData
aaa aaa
bbb bbb
ccc ccc ccc
Actual result
insertData aData bData
aaa
ccc ccc ccc

And so on The contents of the common table have changed.

Fixed (success)

public void putMain()  {
        Map<String, Object> insertData = new HashMap<>();
        insertData.put("aaa","aaa");
        insertData.put("bbb","bbb");
        insertData.put("ccc","ccc");
        putA(insertData);
        putB(insertData);
}
public void putA(Map<String, Object> insertData)  {
        Map<String, Object> aData = new HashMap<>(insertData);
        aData.remove("bbb");
        insert(aData);
}
public void putB(Map<String, Object> insertData)  {
        Map<String, Object> bData = new HashMap<>(insertData);
        bData.remove("aaa");
        insert(bData);
}

Instead of assigning after declaring xData If you give insertData as an argument when declaring xData It worked as expected.

At the end

I haven't studied why this is so, so I don't know. .. .. Please tell me your seniors > <

Recommended Posts

About the matter that I was addicted to how to use hashmap
I was addicted to the roll method
I was addicted to the Spring-Batch test
The operator that was born to be born, instanceof (Java) ~ How to use the instanceof operator ~
I was curious about how to use Optional orElse () and orElseGet () properly.
I was addicted to the NoSuchMethodError in Cloud Endpoints
Java9 was included, so I tried jshell.
I was curious about how to use Optional orElse () and orElseGet () properly.
I was curious about all_month and read ActiveSupport DateAndTime :: Calculations
I tried source code analysis
About the matter that I was addicted to how to use hashmap
I was addicted to the record of the associated model
How to use Maven that I can't hear anymore
What I was addicted to when introducing the JNI library
I was addicted to looping the Update statement on MyBatis
I was addicted to the setting of laradock + VSCode + xdebug
What I was addicted to with the Redmine REST API
The story I was addicted to when setting up STS
How to use the link_to method
How to use the include? method
How to use the form_with method
How to use the wrapper class
I thought about how to use Swift's willSet did Set properly.
I was addicted to the API version min23 setting of registerTorchCallback
[Java] How to use the File class
[Java] How to use the hasNext function
[Rails] How to use the map method
I was addicted to rewriting to @SpringApplicationConfiguration-> @SpringBootTest
[Java] How to use the toString () method
[Processing × Java] How to use the loop
[Processing × Java] How to use the class
[Processing × Java] How to use the function
[Rails] How to solve ActiveSupport :: MessageVerifier :: InvalidSignature that I was addicted to when introducing twitter login [ActiveStorage]
[Java] How to use the Calendar class
How to deal with the type that I thought about writing a Java program for 2 years
A memo that was soberly addicted to the request of multipart / form-data
[Bootstrap] How to use the "grid system" that supports responsive web design
Memorandum: What I was addicted to when I hit the accounting freee API
[Rails] I was addicted to the nginx settings when using Action Cable.
A story I was addicted to when testing the API using MockMVC
My.cnf configuration problem that I was addicted to when I was touching MySQL 8.0 like 5.7
Problems I was addicted to when building the digdag environment with docker
Recorded because I was addicted to the standard input of the Scanner class
I was addicted to scrollview because I couldn't tap the variable size UIView
[CircleCI] I was addicted to the automatic test of CircleCI (rails + mysql) [Memo]
I was addicted to unit testing with the buffer operator in RxJava
A story that I was addicted to twice with the automatic startup setting of Tomcat 8 on CentOS 8
I was addicted to using RXTX on Sierra
How to use the camera module OV7725 (ESP32-WROVER-B)
[Java] How to use Thread.sleep to pause the program
How to use an array for HashMap keys
I was addicted to installing Ruby/Tk on MacOS
Output of how to use the slice method
I was addicted to doing onActivityResult () with DialogFragment
How to use the replace () method (Java Silver)
[Ruby basics] How to use the slice method
I was addicted to not being able to connect to AWS-S3 from the Docker container
I was a little addicted to the S3 Checksum comparison, so I made a note.
I tried to summarize again the devise that was difficult at first sight
How to get the date from the JavaScript Date type that C # developers are addicted to
Today's learning that I was worried about DB design
About the matter that the code to read the C structure member (Char array) that was working in swift 2.3 in swift 3 did not work
How to use Map
[Swift] How to simply describe dismiss that was not taught in the introductory book
How to use rbenv