S
S
Stanislav Korolevskiy2017-10-22 22:23:25
Java
Stanislav Korolevskiy, 2017-10-22 22:23:25

How to write such a Swift construct in Java?

How to write in Java? Here is an example in Swift:

private let sections: [(title: String, description: String)] = [(title: "title1", description: "description1"), (title: "title2", description: "description2")]

This is an ordered array of tuples. Next, I fill the tableView with this array (in java - listView). This is how it looks in Xcode:
cell.titleLabel?.text = self.sections[(indexPath as NSIndexPath).row].title
cell.descriptionLabel?.text = self.sections[(indexPath as NSIndexPath).row].description

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gornostaev, 2017-10-23
@korolevsky_s

public class Section {
    private String title;
    private String description;

    public Section(String title, String description) {
        setTitle(title);
        setDescription(description);
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getTitle() {
        return title;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }
}

List<Section> sections = new ArrayList<>();
sections.add(new Section("title1", "description1"));
sections.add(new Section("title2", "description2"));

A
aol-nnov, 2017-10-22
@aol-nnov

(corrected)
ok then

@Getter
@Setter
@AllArgsConstructor
public class Data {
  private String title;
  private String description;
}

private List<Data> sections = new ArrayList<>();
sections.add(new Data("title1", "description1"));
sections.add(new Data("title2", "description2"));

so gallery?
// never swift developer

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question