Can we create primitive arrays like byte array or int array using javax.script?
Asked
Active
Viewed 3,362 times
3
-
1You either create the array in Java the normal way or you create it in the scripting language. How you do that depends on the language scripted. – Peter Lawrey Nov 14 '12 at 09:30
2 Answers
7
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.

Tomasz Gawel
- 8,379
- 4
- 36
- 61
1
If you are using the JavaScript
engine of the package, use
var array = new Array();
array[0] = 1;
I'd recommend a reading through

Sri Harsha Chilakapati
- 11,744
- 6
- 50
- 91
-
Basically, it needs to be an array of 1024 bytes size. In Java, it used to be byte[] bytes = new byte[1024]; But in javax.script with javascript, I can not find a way to do this. – Meera Menon Nov 15 '12 at 09:50