0

I want to create a struct and after create a array of that struct like in C#.
Exactly like this sample in C#:

public struct factor
    {
        public doubledoor_lenth;
        public string current_model;
        public string current_number;
    }
    factor[] myarr= new factor[100];

I tried it in android studio and I can create the struct correct but I cant create array of it, please help me.

3
  • Where did you find struct in java thats my biggest question !! Commented Mar 26, 2018 at 7:43
  • I can create the struct correct --> How did you do this in android studio?. use class. Commented Mar 26, 2018 at 7:43
  • maybe you should replace 'struct' with 'class'. Commented Mar 26, 2018 at 7:44

2 Answers 2

3

I guess that you failure both of creating a struct and define a new array of it. However, Android Studio just check the Array error first.

The solution is to change it into class because that Java does not have any struct.

> Factor.java
class Factor {
    public double door_lenth;
    public String current_model;
    public String current_number;
}

> SomeClass#Method()
Factor[] myarr = new Factor[100];
Sign up to request clarification or add additional context in comments.

Comments

0

Just use this:

public class factor {
        public double door_lenth;
        public string current_model;
        public string current_number;
}

factor[] myarr= new factor[100];

2 Comments

How did you create a new class-leading by lower case? The same question with the String in Java.
If you are asking how to create it, then it is perfectly fine. There should be no problem with the syntax, just copy the code and paste to your editor. If you want to remind about coding convention, say it nicely.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.