Meera Menon
Meera Menon

Reputation: 69

How to create and use byte array with javax.script

Can we create primitive arrays like byte array or int array using javax.script?

Upvotes: 3

Views: 3601

Answers (2)

Tomasz Gawel
Tomasz Gawel

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

Sri Harsha Chilakapati
Sri Harsha Chilakapati

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

Related Questions