How to Find Array Names in a Set 
June 27th, 2008, 05:17 PM
| | | |
Hello,
I have a series of arrays that I inserted into a HashSet. Now I want to
find out whether a particular array is contained in the set; how do I do
that? Here is what the code looks like:
double array1 = {1.0, 2.0, 3.0, ...};
double array2 = {1.0, 2.0, 3.0, ...};
double array3 = {1.0, 2.0, 3.0, ...}; | 
June 27th, 2008, 09:25 PM
| | | | re: How to Find Array Names in a Set
I'm not sure if I understand your question correctly, but I think you want
to use a HashMap, not a HashSet.
A HashMap allows you to identify the content by something else, such as a
name. Quote:
double array1 = {1.0, 2.0, 3.0, ...};
double array2 = {1.0, 2.0, 3.0, ...};
double array3 = {1.0, 2.0, 3.0, ...};
>
Set<String, double[] hs = new HashMap<String, double[]>();
hs.put("array1", array1);
hs.put("array2", array2);
hs.put("array3", array3);
.
// Retrieve name of array, say arrayX, from a text field.
>
// ArrayX will not be found because arrayX is a String and Array1, etc,
are array objects.
if (hs.contains("array1")) { // How do I test for arrayX?
double [] some_array = hs.get("array1");
}
|
"Jazz Kyat" <technewsie@comcast.netwrote in message
news:fISdnS_Zb7KojKbVnZ2dnUVZ_u-dnZ2d@comcast.com... Quote:
Hello,
>
I have a series of arrays that I inserted into a HashSet. Now I want to
find out whether a particular array is contained in the set; how do I do
that? Here is what the code looks like:
>
double array1 = {1.0, 2.0, 3.0, ...};
double array2 = {1.0, 2.0, 3.0, ...};
double array3 = {1.0, 2.0, 3.0, ...};
.
.
.
>
Set<double[] hs = new HashSet<double[]>();
hs.add(array1);
hs.add(array2);
hs.add(array3);
.
.
.
>
// Retrieve name of array, say arrayX, from a text field.
>
// ArrayX will not be found because arrayX is a String and Array1, etc,
are array objects.
if (hs.contains(arrayX)) { // How do I test for arrayX?
...
}
>
>
| | 
October 3rd, 2008, 03:35 AM
| | | | re: How to Find Array Names in a Set
一件垃圾QQ:361975335, 代*骗* http://forum2.kingofcoders.com/viewt...%3D1&frombbs=1
Jazz Kyat 提到: Quote:
Hello,
>
I have a series of arrays that I inserted into a HashSet. Now I want to
find out whether a particular array is contained in the set; how do I do
that? Here is what the code looks like:
>
double array1 = {1.0, 2.0, 3.0, ...};
double array2 = {1.0, 2.0, 3.0, ...};
double array3 = {1.0, 2.0, 3.0, ...};
.
.
.
>
Set<double[] hs = new HashSet<double[]>();
hs.add(array1);
hs.add(array2);
hs.add(array3);
.
.
.
>
// Retrieve name of array, say arrayX, from a text field.
>
// ArrayX will not be found because arrayX is a String and Array1, etc, are
array objects.
if (hs.contains(arrayX)) { // How do I test for arrayX?
...
}
>
>
| |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 225,714 network members.
|