topics

全部话题 - 话题: arraylist
1 2 3 4 5 末页 (共10页)
b*********n
发帖数: 1258
1
来自主题: Java版 - java ArrayList 一问 (转载)
【 以下文字转载自 Programming 讨论区 】
发信人: babyfacenan (黑土), 信区: Programming
标 题: java ArrayList 一问
发信站: BBS 未名空间站 (Tue Apr 1 03:38:11 2008)
发现一个 ArrayList 很奇怪的现象
一个 ArrayList X
和一个 ArrayList> Y
想要实现: Y = [X, X]
ArrayList X = new ArrayList();
ArrayList> Y = new ArrayList>();
X.add(Double.valueOf(0)); // 先set X
X.add(Double.valueOf(1));
Y.add(X); // 把 X 加入 Y
System.out.println(Y);
X.set(0,Double.valueOf(0.5)); // 然后修改 X :
b*********n
发帖数: 1258
2
来自主题: Programming版 - java ArrayList 一问
发现一个 ArrayList 很奇怪的现象
一个 ArrayList X
和一个 ArrayList> Y
想要实现: Y = [X, X]
ArrayList X = new ArrayList();
ArrayList> Y = new ArrayList>();
X.add(Double.valueOf(0)); // 先set X
X.add(Double.valueOf(1));
Y.add(X); // 把 X 加入 Y
System.out.println(Y);
X.set(0,Double.valueOf(0.5)); // 然后修改 X :
X.set(1,Double.valueOf(1.5));
Y.add(X); // 再把 X 加入 Y
System.out.println(Y);
应该是第一次打印的 Y 是 : [[0, 1]]
第二次打印的 Y 是 : [[0, 1], [0.5, 1.
c*o
发帖数: 70
3
来自主题: DotNet版 - ArrayList??
When I want to add an arrayList's content to another ArrayList,i.e.
al.add(alSon), C# adds the reference of alSon rather than its value to al. Any
one know how to figure it out if I only want to add a content of alSon to al,
and then the content of alSon will be refreshed and added to the al in a loop?
Currently, because the reference of alSon is used, so only duplicated values
of the last asSon are added to al.
Thank you!
ArrayList al=new ArrayList()
ArrayList alSon=new ArrayList()
for (...){
s*******y
发帖数: 558
4
下面这个例子里面 makenull函数传入一个ArrayList的instance, 在函数里把它
设为null, 但是函数返回后, main函数里的这个instance并不为null.
这是为什么阿?
public class test {
public static void makenull(java.util.ArrayList s){
s = null;
}
public static void main(String[] args) {
java.util.ArrayList s = new java.util.ArrayList();
test.makenull(s);
// after test.makenull function, s is NOT null
}
}
s*******y
发帖数: 558
5
thanks a lot
但是你们的解释还是没法说服我
我看到下面这样的解释 觉得比较明白叻
public class MyApp {
public static void makenull(java.util.ArrayList c) {
// c - is a new refference on object of ArrayList class
// value of c refference is same as in s
// so you have two reffeneces on same object
c=null; // here you make c (one of this refference) as null
}
public static void main(String[] args) {
java.util.ArrayList s = new java.util.ArrayList();
MyApp.makenull(s);
//s - is still reffere
o***g
发帖数: 2784
6
you should
for (ArrayList al : newArray)
{
al = new ArrayList();
}
first.
after ArrayList newArray[] = new ArrayList[5];
you only have an array of 5 nulls.
W***o
发帖数: 6519
7
来自主题: Java版 - 问个ArrayList的问题
在练习ArrayList,在网上找题目做,有一个题目是:有个String形式ArrayList,要求
删除这个list里面所有String length 是偶数的 string,我写了下面这个代码,但是运
行起来只能pass 50% of the test. 个人感觉是ArrayList.remove() 之后,List里面
的Index number发生了变化,所以出现错误,请大侠指点一下。我在想这个是不是需要
recursive方法?
public static void removeEvenLength(ArrayList strA)
{
for(int i = 0; i < strA.size(); i++)
{
String stri = strA.get(i);
if(stri.length() % 2 == 0) strA.remove(i);
}

}
l***i
发帖数: 168
8
如果是很大的object,加入一个ArrayList,是不是在随便什么地方allocate足够的内
存建立这个object,然后把object的一个pointer加入ArrayList。只有当这个pointer
的ArrayList所在的内存不够的时候才会另外找更大的地方,并把整个ArrayList复制过
去再延长。
如果是同样的object,使用LinkedList,是不是不用对这个object额外建立一个
pointer。也是在随便什么地方allocate足够的内存建立这个object,然后把
LinkedList上一个element的next指向这个object就行了。
谢谢。
c******n
发帖数: 710
9
只要用到ArrayList,Stack,Queue,就编译不过。
错误如下:
./Solution.java:2: cannot find symbol,symbol : class ArrayList,location:
class Solution, public ArrayList letterCombinations(String digits
) {, ^,1 error
谢谢
r*****l
发帖数: 2859
10
You can not make the ArrayList null in this example. While if you want to
just clear the ArrayList, this works:
public static void makeEmpty(java.util.ArrayList s) {
s.clear();
}
BTW: makenull is not a good name, make it makeNull, using the java
convention.
m******o
发帖数: 774
11
Working on converting a rmi call to web service. The converting itself is no
big deal until I found out the returned value is a HashMap that has 7
ArrayLists. Each of these ArrayList has multiple 'regular' objects (A class
that describes a working shift), and each of these objects contains two more
ArrayLists, one contains classes that describe each segment of this shift
and the other describes related breaks and lunches, etc.
I plan to go the dumb way to convert this stupid thing to a big Strin
r***d
发帖数: 79
12
ArrayList> ary
想只道ary有多少行。 尝试了ary.length()报错
(ArrayList)ary.length()也不对,请问大家是怎么实现的啊?多谢了!
r***d
发帖数: 79
13
ArrayList> ary
想只道ary有多少行。 尝试了ary.length()报错
(ArrayList)ary.length()也不对,请问大家是怎么实现的啊?多谢了!
A*****i
发帖数: 3587
14
vector只能用迭代来取值和删除值,和arraylist还是不一样的
确实C++没有这种实现,不过可以用hash+vector来做
或者arraylist怎么来的应该都知道,同样的方法在C++里面做一个就可以
WB
发帖数: 170
15
来自主题: DotNet版 - about ArrayList
平时用ArrayList ,在内存读取大量数据,性能应该比数据库好吧?
ArrayList的数据如何导入到数据库?
Q**g
发帖数: 183
16
你是不是放错东西到p里头了?下面这段是work的
ArrayList p = new ArrayList();
for (int i=0;i<10;i++)
p.add(""+i);
String[] s = new String[p.size()];
for (int i=0;i< p.size(); i++){
s[i] = (String)p.get(i);
}

for (int i=0;i System.out.println(s[i]);
n*****n
发帖数: 100
17
也就是说,能不能定义:
ArrayList newArray[]=new ArrayList[5].
好像这样定义JAVA是认可的,但是当读newArray的东西的时候就出问题了。比如不能操
作:
for (int i=0;i ...
}
多谢指教!
T*********e
发帖数: 9208
18
来自主题: Java版 - java ArrayList 一问 (转载)
Array.add加的是reference.
ArrayList X2 = new ArrayList();
Y.add(X2);
O*z
发帖数: 109
19
最近在看Horstmann写的那本Core Java自学,好像看了书之后做练习的时候有很多自己
找出的问题。比如帖子题目写的
这两个对比。我在看了Java API之后,觉得ArrayList的methods可能更多,而且还能转
成Array(除了Integer等类似primitive type的不能转意外(???有待考证))
对于String和Stringbuffer我自己的体会是string是immutable,但是StringBuffer是
可以改变其中string的内容,而且看过API之后感觉StringBuffer这个class自带的
methods更多更实用一些。
请高手指点一下。
还有最后一个问题,Java中的每个class(比如string, arrayList)有这么多methods,
大家是一般都能记住,还是只记住几个很常用的,其他不太常用的methods在有需要的
时候去看API的?不好意思,问题好像挺多的,请各位不吝赐教
t***a
发帖数: 416
20
也不能说完全是两回事, ArrayList内部存储是个Array
可以把arraylist想象成为一个实现了List接口的可以自己增长capacity的array
s****A
发帖数: 80
21
CareerCup里ArrayList的题,如果自己不会Java只会C++
该怎么办?
WB
发帖数: 170
22
来自主题: DotNet版 - ArrayList如何保存到文件?
ArrayList里面保存不少结构变量,
想保存到文件,怎样序列化比较好?
cs的结构数据数组怎么保存文件好?
有点类是c的记录文件的cs实现
WB
发帖数: 170
23
如何反序列化到arraylist?如何检索
序列化文件中的对象/数据
a*******9
发帖数: 160
24
来自主题: DotNet版 - 请问arraylist的问题。
我把一串ID 存到arraylist里面。每个ID对应database里面一个row,每个row都有好几
个项目的信息。
请问我能否只通过这个ID就可以把对应row的数据都显示出来?通过什么方式?非常感
m*****j
发帖数: 499
25
来自主题: DotNet版 - 请问arraylist的问题。
arraylist不是generics,楼上提的Dictionary挺好的
可以考虑用Dictionary>
w***y
发帖数: 6251
26
假如已经有了一个Arraylist p, 里面的元素其实是一些string
我想转成一个String[]
String[] y = new String[p.size()];
for ( i=0;i< p.size(); i++){
y[i] = (String)p.get(i);
}
可是执行到y[i] = (String)p.get(i);总是有 java.lang.ClassCastException
怎么回事呢?
我还试了String[] predators = (String[])al.toArray( new String[ al.size() ] );
这样的, 但是error是 java.lang.ArrayStoreException:((
thx
xt
发帖数: 17532
27

You are welcome.
Remember this does not solve your problem, if you intend to use that
ArrayList to store String but you get sth else in it.
w***y
发帖数: 6251
28
【 以下文字转载自 Programming 讨论区 】
【 原文由 woomy 所发表 】
javascript能访问JSP里的arraylist么? 我google了半天也没找到怎么实现:(
thx a lot!
m**c
发帖数: 90
29

Only staticaly:
<%
List list = new ArrayList();
...
%>
....

...
m******d
发帖数: 3243
30
来自主题: Java版 - ArrayList and Link list
What are the differences between arraylist and linked list?
Thanks
n*****n
发帖数: 100
31
exactly true!
I need to initialize the array with assigning an arrayList to each array
element. Thanks a lot.
A**o
发帖数: 1550
32
这是Array初始化的问题,你不过正好用了ArrayList。
z***h
发帖数: 405
33
来自主题: Java版 - java ArrayList 一问 (转载)
has nothing to do ArrayList
J*G
发帖数: 6
34
来自主题: Java版 - 超级初级问题ArrayList
超级Java新手,请问大家一个问题:
I defined a dynamic array as follows:
protected ArrayList listABC = null;
在constructor里面,下面一行complain:
this.listABC.add(astrTemp);
where astrTemp is an array of string (type String[]).
超级新手,第2天学Java做一个project,不知道上面implementation有啥问题。。
谢谢大家!
m******o
发帖数: 774
35
I created the web service using annotation @WebService, etc. It appears that
a wsdl file is created automatically when the code is deployed within JBoss
. The wsdl file specifies that the return type of this web service method
would be 'hashMap'. However when the method is being called, an error is
thrown saying 'hashMap' is not a recognized type. I googled around and it
does look like HashMap,ArrayList etc. are no longer supported by current web
service specification. I assume java2wsdl would f
m******o
发帖数: 774
36
Are you saying to have a wrapper class that contains two arrays? Would it
work if each element of the value array also contains the unsupported
ArrayList?
r******r
发帖数: 700
37
不是高手,Array 和 ArrayList 完全是两码事。
Methods 很多,但是常用的好像不太多。
z*******3
发帖数: 13709
38
ArrayList 是 List,记List的方法
Array这个类我好久没见到了,上一次见到是Array.asList()
StringBuffer理论上效率要高于String
不过我也没有见过多少人用它
g*****g
发帖数: 34805
39
ArrayList is backed by an array, in case you need high performance, a good
initialization parameter matters.
Array is only for reflection, you are probably talking about Arrays.
F*******X
发帖数: 143
40
我也在自学中,看了数本书都提到 ArrayList, 但没有看到 Array,我想这 Array 应
该用的不多。关于 StringBuffer 和 String 应该是看你怎么用吧!关于 methods,我
也有相同的感觉,太多太难记,但有些书会说只有某些 class 的 methods 是常用的,
记着就好,其他的要用的就自己看 doc, 不知道实际工作是怎样的状况?
F*******X
发帖数: 143
41
我是说 Array class 很少在书里看到。 很多初级 Java 书都先教 ArrayList 然后再
讲解 Generic
p*****2
发帖数: 21240
42
来自主题: Java版 - 问个ArrayList的问题
ArrayList的remove复杂度太高了。
W***o
发帖数: 6519
43
来自主题: Java版 - 问个ArrayList的问题
谢谢各位的回复,根据提示写了下面的代码,现在终于works了,谢谢!!
public static void removeEvenLength(ArrayList strA)
{
Iterator i = strA.iterator();
while(i.hasNext())
{
String stri = i.next();
if((stri.length() % 2) == 0) i.remove();
}


}
f**r
发帖数: 865
44
来自主题: Java版 - 问个ArrayList的问题
en, 这种情况不应该用ArrayList
d****n
发帖数: 1637
45
来自主题: Programming版 - go为什么没有arraylist?
你要是看过了就会更明白不会再问了。
append arrayList by make
malloc+realloc
what is your answer?
l****o
发帖数: 315
46
来自主题: JobHunting版 - 关于leetcode的combinationSum题
可过
public class Solution {
public ArrayList> combinationSum(int[] candidates,
int target) {
// Start typing your Java solution below
// DO NOT write main() function

Arrays.sort(candidates);
ArrayList>> f = new ArrayList >>();
for (int i = 0; i <= target; i++) {
ArrayList> tmp = new ArrayList Integer>>();
f.add(tmp);... 阅读全帖
d******l
发帖数: 175
47
来自主题: JobHunting版 - 请教LeetCode的3Sum
大家好,我纠结这道题目一些时间了。期间用Java写了3个算法,在Judge Large的时候
都说超时。请教高人帮忙分析一下我的一个算法的复杂度(基于TwoSum的一个解法)。
非常感谢。
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
public class Solution {
public ArrayList> twoSum(int[] numbers, int target) {
ArrayList> twoSumList = new ArrayList Integer>>();
Map map = new HashMap();
for (in... 阅读全帖
S*******C
发帖数: 822
48
http://oj.leetcode.com/problems/subsets/
第一种格式:res作为局部变量避免线程安全问题,但比较啰嗦
public ArrayList> subsets(int[] num){
if(num==null) return null;
Arrays.sort(num);
ArrayList> res=new ArrayList>(
);
res.add(new ArrayList());// [[]]
dfs(res, num,0,new ArrayList());
return res;
}
private void dfs(ArrayList> res, int[] num, int pos,
ArrayList temp){... 阅读全帖
c********l
发帖数: 8138
49
来自主题: JobHunting版 - Leetcode的系统真是弱爆了
//MITBBS' article system will mess up the source code
// You may probably need to re-arrange the line breaks
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class Solution {

public static void main(String[] args) {
Solution sol = new Solution();
String[] dictStrArr = new String[] {
"dose","ends","dine","jars","prow","soap","guns","hops","
cray","hove","ella","hour","lens","j... 阅读全帖
c********l
发帖数: 8138
50
简洁不是最终极的目标,有时候需要reduce runtime complexity
见我之前写的
http://www.mitbbs.com/article/JobHunting/32658475_3.html
//MITBBS' article system will mess up the source code
// You may probably need to re-arrange the line breaks
// by coupondeal@mitbbs
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public class Solution {

public static void main(String[] args) {
Solution sol = new Solution();
String[] dictStrA... 阅读全帖
1 2 3 4 5 末页 (共10页)