Java questions about value references, address references

Source: Internet
Author: User

8 Basic Reference types

Four types of integers (byte, short, int, long)

Two types of floating-point numbers (float, double)

A character type (char)

A Boolean type (Boolean)

As well as data types such as String, final type.

When a method is called, the value is passed, and the value is changed in the method, and the original value does not change.

In addition to the above data types, such as custom objects, references such as map,list, are address references.

The following demo:

Importjava.util.ArrayList;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map;/** * @authorLiyuechao * *@since: August 10, 2017 pm 5:12:07*/ Public classTest { Public Static voidMain (string[] args) {List<A> list =NewArraylist<>(); A A=NewA (); A.setname (A); A b=NewA (); B.setname ("B");        List.add (a);        List.add (b); Map<string, list<a>> map =NewHashMap (); Map.put ("Ha", list);
Null does not change because there is no specific point to address map.put ("He",NULL); List<A> lista = map.get ("Ha"); List<A> LISTC = Map.get ("Ha"); List<A> listd = Map.get ("he"); for(A a2:lista) {Modi (A2); } setValue (LISTD); List<A> Listb = Map.get ("Ha"); for(A a2:listb) {System.out.println (A2.getname ()); } for(A a2:listc) {System.out.println (A2.getname ()); } for(A a2:listd) {System.out.println (A2.getname ()); } } Public Static voidModi (a a) {A.setname ("X"); } Public Static voidSetValue (list<a>list) { if(List = =NULL) List=NewArraylist<>(); A A=NewA (); A.setname ("Y"); List.add (a); }}/** * @authorLiyuechao * *@since: August 10, 2017 pm 5:12:31*/ Public classa{PrivateString name; PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; }}

Operation Result:

Java questions about value references, address references

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.