Try the following:
library(rJava)
.jinit()
hm<-.jnew("java/util/HashMap")
.jrcall(hm,"put","one", "1")
.jrcall(hm,"put","two","2")
.jrcall(hm,"put","three", "3")
keySet<-.jrcall(hm,"keySet")
an_iter<-.jrcall(keySet,"iterator")
aList <- list()
while(.jrcall(an_iter,"hasNext")){
key <- .jrcall(an_iter,"next");
aList[[key]] <- .jrcall(hm,"get",key)
}
Please note that using .jrcall is less efficient than .jcall. But for the life of me I cannot get a signature by using .jcall. I wonder if this is due to the lack of generics.
source
share