Contenido principal

com.mathworks.toolbox.javabuilder.MWStringArray Class

Namespace: com.mathworks.toolbox.javabuilder

Java class to manage MATLAB string arrays

Description

Declaration

public class MWStringArray extends MWArray

The MWStringArray class manages a native MATLAB® string array.

Implemented Interfaces: Disposable, java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

Runtime Dependency and Initialization Requirements

MWArray API types represent native MATLAB arrays and are intended for use when MATLAB Runtime is available as part of Java® Package Integration. To ensure MATLAB Runtime is ready, instantiate the generated class or initialize runtime configuration before invoking packaged code.

Instantiating a class from the Java package generated by MATLAB Compiler SDK™ is the recommended method to ensure the runtime is started. Calling com.mathworks.toolbox.javabuilder.MWApplication.initialize prepares the process environment but does not start MATLAB Runtime. If the runtime is not started by a class instantiation, MWStringArray constructors will fail.

This class is only supported for in-process execution. It cannot be used when working with an out-of-process MATLAB Runtime.

If you cannot instantiate an object from the generated Java package before creating an array, use the MWCharArray class to pass character data. Alternatively, include a method in your MATLAB code that performs no operation and invoke it immediately after instantiating the Java class to trigger the runtime startup.

Creation

MWStringArray()

Creates an empty string array. Requires an active MATLAB Runtime.

MWStringArray(int[] dims)

Creates an n-dimensional string array with all elements set to the default value. Requires an active MATLAB Runtime.

MWStringArray(java.lang.String val)

Creates a one-element string array that represents the Java string argument. Requires an active MATLAB Runtime.

MWStringArray(java.lang.String[] vals)

Creates a string array that represents the Java string array argument. Requires an active MATLAB Runtime.

Properties

expand all

Public Properties

A convenient, efficient, and consistent way to represent an empty array as follows:

public static final MWArray EMPTY_ARRAY

Methods

expand all

Examples

collapse all

To use MWStringArray correctly, you must first instantiate the Java class created from your MATLAB code.

// Initialize the application environment
MWApplication.initialize();

// Instantiate the class from the generated Java package to start MATLAB Runtime
// Replace 'MyPackageClass' with the actual class name in your generated package
MyPackageClass component = new MyPackageClass();

// Now MWStringArray can be safely created
MWStringArray A = new MWStringArray("Hello World");
System.out.println(A.toString());

// Dispose of objects
A.dispose();
component.dispose();

Version History

Introduced in R2006a