- #1
kolleamm
- 477
- 44
Homework Statement
How can I store String s in X x_obj [] = new X [100] ;2. What I tried
I tried
x_obj [0] = s;
But it didn't work. I know there are easier ways but this is how I have to do it.
Thanks in advance
void setup() {
Object[] x = new Object[100];
String s = "hello";
x[0]=s; // Object is the parent class to all java classes
println("x[0]="+x[0]);
}
void setup() {
Float[] x = new Float[100];
String s = "hello";
x[0]=(Float)s; // fails with can't cast String to Float
println("x[0]="+x[0]);
}
The language is Java, apologies I completely forgot to mention itBvU said:How did you guess the language ? I thought better of asking OP for it since that would have thrown the thread off the unanswered list...
To store a string in a created object type, you can create a property within the object and assign the string as its value. For example, you can use the dot notation or bracket notation to create a property named "string" and assign the string value to it.
Yes, you can store multiple strings in an object by creating multiple properties and assigning string values to each of them.
To access the stored string in an object, you can use the dot notation or bracket notation and specify the property name that contains the string value. This will return the string value stored in that property.
Yes, you can change the stored string in an object by reassigning a new string value to the corresponding property. If the property already exists, the new string value will replace the previous one. If the property doesn't exist, a new property will be created with the assigned string value.
To delete a stored string in an object, you can use the delete keyword followed by the object name and property name. This will remove the specified property and its corresponding string value from the object.