JAVA与JAVASCRIPT数组内存空间分配区别
public class j1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] books=new String[]
{"java","javaee","ajax","xml",
};
String[] names={
"1","2","3",
};
String[] atrArr=new String[5];
System.out.println("first "+books.length);
System.out.println("two "+names.length);
System.out.println("third "+atrArr.length);
books=names;
atrArr=names;
System.out.println("\n\n\nfirst "+books.length);
System.out.println("two "+names.length);
System.out.println("third "+atrArr.length);
books[1]="小孩";
System.out.println("----------------");
System.out.println("books第二个: "+books[1]);
}
}
-----------------javascript数组
<html>
<head>
<title></title>
</head>
<body>
<script type="test/javascript">
var arr = [];
document.writeln("arr长度:" + arr.length + "<br/>");
arr[2]=6;
arr[10]="帅哥";
arr[12]=2;
arr[18]="44";
document.writeln("arr长度:" + arr.length + "<br/>");
</script>
</body>
</html>
-------------------
JAVA不可自动增加内存空间.
JAVASCRIPT可以自动增加内存空间.
--------------------
public class j1 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String[] books=new String[]
{"java","javaee","ajax","xml",
};
String[] names={
"1","2","3",
};
String[] atrArr=new String[5];
System.out.println("first "+books.length);
System.out.println("two "+names.length);
System.out.println("third "+atrArr.length);
books=names;
atrArr=names;
System.out.println("\nfirst "+books.length);
System.out.println("two "+names.length);
System.out.println("third "+atrArr.length);
books[2]="小孩";
atrArr[2]="无所谓";
System.out.println("----------------");
System.out.println("books第二个: "+books[1]);
System.out.println("first "+books.length);
System.out.println("two "+names.length);
System.out.println("third "+atrArr.length);
System.out.println("third "+atrArr[2]);
}
}
-------------out
first 4
two 3
third 5
first 3
two 3
third 3
----------------
books第二个: 2
first 3
two 3
third 3
third 无所谓
-----------------------javascript
<html>
<head>
<title></title>
</head>
<body>
<script type="test/javascript">
var arr = [];
document.writeln("arr长度:" + arr.length + "\n");
arr[2]=6;
arr[10]="帅哥";
arr[12]=2;
arr[18]="44";
document.writeln("arr长度:" + arr.length );
</script>
</body>
</html>
----------------out
0
19
补充:软件开发 , Java ,