由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Java版 - VECTOR一问
相关主题
Java是如何处理ArrayList和LinkedList的内存的?open source java programs/tools database
类里的字符串向量赋值,总报错:如何删除 linked list 的最后一个元素
How to find function pointers in Java?一个bug竟然是legacy code埋的地雷。
Top Ten Errors Java Programmers Make(1)EJB ConnectionFactory issue
Re: question:linked list?问个C++的问题
Re: How to find function pointers in Javc++ 里面 this pointer 是完全 un necessary 的吗? (转载)
来来来,给偶解决一个问题C++ Function Pointer Array 的问题
how to run Java on Linux?请教个C++的问题
相关话题的讨论汇总
话题: vector话题: double话题: svec话题: stree话题: after
进入Java版参与讨论
1 (共1页)
m*******o
发帖数: 264
1
import java.util.*;
public class test {
public static void main(String args[]){
double S=100.0;

Vector> Stree = new Vector>();
Vector Svec = new Vector();

Svec.add(S);
Stree.add(Svec);
Svec.add(S+1);
Stree.add(Svec);


System.out.println("After loop Stree 0 is "+Stree.get(0));
System.out.println("After loop Stree 1 is "+Stree.get(1));
}
}
h*********o
发帖数: 62
2
vector in java is both sorted and ordered.
h**j
发帖数: 2033
3
SVec is a reference

【在 m*******o 的大作中提到】
: import java.util.*;
: public class test {
: public static void main(String args[]){
: double S=100.0;
:
: Vector> Stree = new Vector>();
: Vector Svec = new Vector();
:
: Svec.add(S);
: Stree.add(Svec);

h**j
发帖数: 2033
4
害人啊

【在 h*********o 的大作中提到】
: vector in java is both sorted and ordered.
h*********o
发帖数: 62
5
how?
h*********o
发帖数: 62
6
my fault. it is only ordered.
m*******o
发帖数: 264
7
怎么没一个人讲明白,VECTOR是动态同步的,所以都一样
可是为什么如果把VECTOR换成ARRAYLIST也是一样的结果?
g*****g
发帖数: 34805
8
我没细看你的程序,但是Vector跟ArrayList的区别就在于
多线程同步保护。你的程序只有一个线程,结果怎么都一样。

【在 m*******o 的大作中提到】
: 怎么没一个人讲明白,VECTOR是动态同步的,所以都一样
: 可是为什么如果把VECTOR换成ARRAYLIST也是一样的结果?

c*****t
发帖数: 1879
9
Well, in Java, all objects are pointers. So you are adding
the pointer to the same vector to Stree. Of course you will
get the same result because you get the same vector pointer.
In C++ vector, it always make a copy of what you pass, in
this case, the reference of the Svec. The result of course
would be different.

【在 m*******o 的大作中提到】
: import java.util.*;
: public class test {
: public static void main(String args[]){
: double S=100.0;
:
: Vector> Stree = new Vector>();
: Vector Svec = new Vector();
:
: Svec.add(S);
: Stree.add(Svec);

c*****t
发帖数: 1879
10
Please do not give false / misleading information.

【在 h*********o 的大作中提到】
: my fault. it is only ordered.
m*******o
发帖数: 264
11
Thanks a lot, but I remember all objects are reference in java, or pointers.
Correct me if I am wrong.
In this java case, is there any way to get the non-same result?

【在 c*****t 的大作中提到】
: Well, in Java, all objects are pointers. So you are adding
: the pointer to the same vector to Stree. Of course you will
: get the same result because you get the same vector pointer.
: In C++ vector, it always make a copy of what you pass, in
: this case, the reference of the Svec. The result of course
: would be different.

c*****t
发帖数: 1879
12

pointers.
You can clone a copy then add.
I'd suggest you to study Java more systematically. It takes less
than a week to do so, but avoids confusions you might have for
a long run.

【在 m*******o 的大作中提到】
: Thanks a lot, but I remember all objects are reference in java, or pointers.
: Correct me if I am wrong.
: In this java case, is there any way to get the non-same result?

1 (共1页)
进入Java版参与讨论
相关主题
请教个C++的问题Re: question:linked list?
看看这个 C 代码Re: How to find function pointers in Jav
请教一个const pointer的问题来来来,给偶解决一个问题
关于delete的一个问题how to run Java on Linux?
Java是如何处理ArrayList和LinkedList的内存的?open source java programs/tools database
类里的字符串向量赋值,总报错:如何删除 linked list 的最后一个元素
How to find function pointers in Java?一个bug竟然是legacy code埋的地雷。
Top Ten Errors Java Programmers Make(1)EJB ConnectionFactory issue
相关话题的讨论汇总
话题: vector话题: double话题: svec话题: stree话题: after