Learn R Programming

J4R (version 1.0.7)

createJavaObject: Create Java objects

Description

This function creates one or many object of a particular class. If the parameters contain vectors, then a series of instances of this class can be created.

Usage

createJavaObject(class, ..., isNullObject = FALSE, isArray = FALSE)

Arguments

class

the Java class of the object (e.g. java.util.ArrayList)

...

the parameters to be passed to the constructor of the object

isNullObject

a logical that indicates whether the instance should be null (by default it is set to FALSE)

isArray

a logical that indicates whether the instance is an array. By default, it is set to FALSE. When creating an array, the parameters must be integers that define the dimensions of the array

Value

a java.object or java.list instance in the R environment

See Also

J4R webpage

Examples

Run this code
# NOT RUN {
### starting Java
connectToJava()

### creating an empty ArrayList object
createJavaObject("java.util.ArrayList")

### creating an ArrayList instance with initial capacity of 3
createJavaObject("java.util.ArrayList", as.integer(3))

### creating two ArrayList with different capacities
createJavaObject("java.util.ArrayList", c(as.integer(3), as.integer(4)))

### creating a 3x3 array of integers
myArray <- createJavaObject("int", 3, 3, isArray = TRUE)

### creating two arrays of integers with length 3
myArrays <- createJavaObject("int", c(3,3), isArray = TRUE)

### shutting down Java
shutdownJava()

# }

Run the code above in your browser using DataLab