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.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Saeed Sheikh
  • 25
  • 1
  • 4

2 Answers2

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];
Kobayashi
  • 106
  • 4
0

Just use this:

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

factor[] myarr= new factor[100];
Cao Minh Vu
  • 1,900
  • 1
  • 16
  • 21
  • How did you create a new class-leading by lower case? The same question with the String in Java. – Trần Đức Tâm Mar 26 '18 at 08:06
  • 1
    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. – Cao Minh Vu Mar 26 '18 at 08:35