P
P
pwnsauce2018-02-27 14:50:30
Java
pwnsauce, 2018-02-27 14:50:30

How to work with data from a file?

Hello,
I need advice. I have a text file like:

Karin Novakova
math
0
11
13
Radmila Svobodova
computers
0
12
14
Diana Novotna
math
0
13
15

and so on .. That is, first comes the Name of the person and 3 numbers belonging to him.
How can I put 5 rows into an array at once? Or what would you recommend to use to store this information?
That is, I will need to have the given in approximately this form:
[person 1] Person name
[person 1] number 1
[person 1] number 2
[person 1] number 3
[person 2] Person name
[person 2] number 1
[person 2] number 2
[person 2] number3
and so on..
what is the best way to store data in such a way that it would be convenient to use?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
piatachki, 2018-02-27
@pwnsauce

Mankind has come up with a cool thing - OOP. Java is perhaps its quintessence.

public class Person {
   private String name;
   private String discip;  // или Enum
   private List<Integer> numbers;  // Или массив, если уверены в количестве чисел на 146% и целеполагание позволяет

....... getters/setters

}

To store and use, without a doubt, it is more convenient that way.

M
MaxLich, 2018-02-28
@MaxLich

I will also add that it is better to store data in the database, and not in files.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question