On Fri, Oct 28, 2005 at 04:53:19PM +0800, PFi...@hb... wrote:
> The java.util.Set interface does not have an array signature. I converted
> the Set collection to an array using the Set.toArray method and accessed
> the array with the javaArrayObjcommand set.
>
> Is there an easy way of converting a java array to a tcl array that can be
> used with lsearch.
>
> For example:
>
> set iteratorI [ $serverSet iterator ]
> set arrayI [ $serverSet toArray ]
>
> puts "\n serverSet array length [ $arrayI length ] \n"
>
> *** set tclList [ convert $arrayI ]
>
> Then use regular tcl commands.
>
> lsearch $tclArray xxx
>
> foreach i $tclArray { puts $i }
probably:
set tclList [list]
set arrayI [ $serverSet toArray ]
foreach obj [$arrayI getrange] {
lappend tclList $obj
# or maybe: lappend tclList [$obj toString]
# depending on what kind of objects are in your Set
}
instead of converting to an array, you could also just use the
iterator, it's a little less messy:
set tclList [list]
set set iteratorI [ $serverSet iterator ]
while {[$iteratorI hasNext]} {
lappend tclList [$iteratorI next]
# may have to cast your object from the iterator, or toString as above,
# again depending on what objects you have in your Set.
# lappend tclList [java::cast xxx.yyy.YourObject [$iteratorI next]]
# lappend tclList [[$iteratorI next] toString]
}
(I *love* the 'java' package in Jacl!)
--
Tom Poindexter
tpo...@ny...
http://www.nyx.net/~tpoindex/
|