- 爱易网页
-
JavaSript
- JAVA与JAVASCRIPT数组内存空间分配差异
日期:2014-05-16 浏览次数:20367 次
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",
};