there are some data sets (in 1C it would be called a collection) for example

1 мерин 25-05-20012 2 аудюха 17-06-2012 3 жигуль 22-06-2012 

How can I pack this into an array (line by line of course) and how can I sort it out?

  • it all depends on the form in which your program receives input data. plain text or reads from a DBMS? - jmu
  • reads a json-string from a DBMS and parses into string variables - baralgin1003

2 answers 2

To create for example a class, well, to access the fields, you must also add getters and setters

 class Record { private int number; private String name,date; public Record(String token) { String[] data = token.split(" "); this.number = Integer.parseInt(data[0]); this.name = data[1]; this.date = data[2]; } } 

Then create

 List<Record> list = new ArrayList<Record>(); 

add

 list.add(new Record(inputString)); 

Walk on it

 for (Record record : list) { ... } 
  • If you do not complicate getters / setters, then the class fields can be declared public, not private. If the size of the array is known in advance (and it is assumed that its contents are simply manipulated), then instead of ArrayList, simply describe the array of objects of your class. In general, @ baralgin1003, first read any book on Java. - avp
  • one
    > In general, @ baralgin1003, first read any book on Java. judging by the given example, not only he needs to read books - jmu
  • 2
    These 2 lines as an example will go? ArrayList <Record> list = new ArrayList <Record> (); List <Record> list = new ArrayList <Record> (); - jmu
  • one
    In principle, nobody was in a hurry. In addition, the time to write a comment you have so there is time to edit the answer. + another nuance with the class itself: Record is an ordinary java bean itself, but you shove a fuctional into it which is not essentially tied to a separate class instance, which means it makes sense to use the factory method. when code review is done in 90% of cases, it can be said that every error found is not significant. on the other hand, their presence / absence allows judging you as a specialist - jmu
  • one
    in fact, this json example does not parse. I would recommend wiki.fasterxml.com/JacksonHome for this purpose - Gautama Buddha

A two-dimensional array in this case is 3 by 3, using a for loop