Reputation: 69
Can we create primitive arrays like byte array or int array using javax.script?
Upvotes: 3
Views: 3601
Reputation: 8520
To create a Java Array of 10 bytes in Mozilla's Rhino:
var buff = java.lang.reflect.Array.newInstance(java.lang.Byte.TYPE, 10)
Notice that java array is different type than native JavScript array - they both can be used in Rhino JavaScript.
Upvotes: 7
Reputation: 11950
If you are using the JavaScript
engine of the package, use
var array = new Array();
array[0] = 1;
I'd recommend a reading through
Java Docs
Java6Master
Java Scripting Programmer's Guide
Upvotes: 1