Connecting Tech Pros Worldwide Help | Site Map

How to Find Array Names in a Set

  #1  
Old June 27th, 2008, 05:17 PM
Jazz Kyat
Guest
 
Posts: n/a
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, ...};
  #2  
Old June 27th, 2008, 09:25 PM
wizard of oz
Guest
 
Posts: n/a

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?
...
}
>
>
  #3  
Old October 3rd, 2008, 03:35 AM
Peter
Guest
 
Posts: n/a

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?
...
}
>
>
Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to find a substring in a string barnacle.steve@gmail.com answers 1 June 27th, 2008 05:29 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 09:56 PM
comp.lang.c Answers to Frequently Asked Questions (FAQ List) Steve Summit answers 0 November 13th, 2005 03:15 AM
sort() array names sequentially with numbers David answers 19 October 1st, 2005 09:55 PM