This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Construct and Concatenate Java Objects

Create Java Object

Many Java® method signatures contain Java object arguments. To create a Java object, call one of the constructors of the class. For an example, see Call Java Method.

Concatenate Objects of Same Class

To concatenate Java objects, use either the cat function or the [] operators.

Concatenating objects of the same Java class results in an array of objects of that class.

value1 = java.lang.Integer(88);
value2 = java.lang.Integer(45);
ans =



Concatenate Objects of Unlike Classes

If you concatenate objects of unlike classes, MATLAB® finds one class from which all the input objects inherit. MATLAB selects the lowest common parent in the Java class hierarchy as the output class. For example, concatenating objects of java.lang.Byte, java.lang.Integer, and java.lang.Double creates an object of the common parent to the three input classes, java.lang.Number.

byte = java.lang.Byte(127);
integer = java.lang.Integer(52);
double = java.lang.Double(7.8);
[byte integer double]
ans =


    [   127]
    [    52]

If there is no common, lower-level parent, then the resultant class is java.lang.Object.

byte = java.lang.Byte(127);
point = java.awt.Point(24,127);
[byte point]
ans =


    [               127]
    [1×1 java.awt.Point]

Related Topics