惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

F
Fortinet All Blogs
Attack and Defense Labs
Attack and Defense Labs
V2EX - 技术
V2EX - 技术
O
OpenAI News
S
Secure Thoughts
H
Heimdal Security Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Schneier on Security
Schneier on Security
H
Hacker News: Front Page
S
Security Affairs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Vercel News
Vercel News
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
P
Proofpoint News Feed
The Register - Security
The Register - Security
GbyAI
GbyAI
Cloudbric
Cloudbric
MongoDB | Blog
MongoDB | Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
K
Kaspersky official blog
Forbes - Security
Forbes - Security
Y
Y Combinator Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
The Cloudflare Blog
Recorded Future
Recorded Future
人人都是产品经理
人人都是产品经理
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
Webroot Blog
Webroot Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LangChain Blog
T
Tor Project blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
Hacker News: Ask HN
Hacker News: Ask HN
Blog — PlanetScale
Blog — PlanetScale
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
B
Blog RSS Feed
N
News and Events Feed by Topic
阮一峰的网络日志
阮一峰的网络日志
I
Intezer
V
V2EX
T
Tailwind CSS Blog
SecWiki News
SecWiki News
NISL@THU
NISL@THU
C
Check Point Blog

博客园 - hone

管理 服务器相关 总统和亿万富翁经典语录(转载) js学习笔记 最近学习计划 VC控制Excel 真乱(转自csdn) 沟通(网上搜集) 工作 无题 将文档发送到打印机(From MSN) 经典68个故事 Manually Invalidating All Stale Sessions java的zip压缩(转自Jeet) 图形相关 在Oracle9i中计算时间差 六度分隔 经典故事 新年竟然第一篇?!
java学习
hone · 2007-04-05 · via 博客园 - hone

Java does not have explicit pointers; in a sense, all variables that refer to objects are pointers. When you assign between two objects of the same type, you actually assign a reference to the object on the right-hand side. To create a new instance of an object, you need to call one of its constructors:

myObject a, b;

= b;                 // reference

= new myObject(b);   // create a new object

In Java, the + operator can concatenate strings together. A sequence such as the following

String greeting = "Hello";
greeting 
= greeting + " there";

 is legal. Because the original String that greeting points to cannot be modified, the concatenation actually involves the creation of a new String, which greeting is then set to point to. Therefore, the reference to the original "Hello" string is removed, which eventually causes it to be destroyed.
The concatenation statement also involves some more behind-the-scenes magic by the compiler. It creates a temporary StringBuffer, then calls the StringBuffer.append() method for each expression separated by a + sign, then calls StringBuffer.toString() to convert it back to the result String. As with the automatic creation of String objects from constant strings, this is a special case on the part of Java, but is there because string concatenation is so useful.

Arrays can also hold objects, so you can declare the following:

MyObject[] objarray;


This would then be created as follows (this could be combined with the declaration):

objarray = new MyObject[5];

It is important to note that this creates only the array. You still need to create the five objects:

for (k = 0; k < 5; k++{

    objarray[k] 
= new MyObject();

}

To create subarrays, create an array where each element is an array. The first array can be declared and created in one step

int[][] bigArray = new int[6][];

and then each subarray needs to be created (each one can be a different length, in fact):

for (m = 0; m < 6; m++{

    bigArray[m] 
= new int[20];

}

You can initialize arrays when they are declared:

short[][] shortArray = 123 },  4 },  5 , 6 } };


After that, shortArray[0] would be an array of three elements,
shortArray[1] would be an array of one element,
and shortArray[2] would be an array of two elements.