Henrikas Butenas wrote:I want to have same information in ArrayList and in text fale. So is there a way to compare them? After comparing them I want to add/remove information from file or array
And if the contents don't match, from which side you are going to crop them, ArrayList or File? Or you going to add to one of these, which one, ArrayList or File? How the decision is being made to delete or remove?
As Campbell told already, tell what is the task in general, don't tell any details about the data structure, i.e.: ArrayList. It is not relevant.
Task may sound:
I have a text file which may contain lots of swear words. The task is to remove them from the text, given that I have the swear words provided by the...
As you described the problem now, it doesn't make sense as simply not clear how to make contents same, we don't see the rationale behind how to make them same. That's probably because not clear what is the task about.
Ok, I will try to explain the task. So I have a building(object), with address, floor level, year of construction and apartments number on one floor. I have to add/remove/edit these objects and I want to have same information about them in ArrayList and in .txt file. And if the contents don't match i will crop from txt file
Henrikas Butenas wrote:So I have a building(object)
In case you have building object in the form of Java object, why do you need to add/remove/edit ArrayList.
Can't you just always ADD to array list the information from Building object, which I presume have correct information?
Can't you do the same with text file, instead of trying to edit something, can't you just write new file with correct information from Building object?
or there is something else you didn't tell us, for instance: text file contains all the city buildings, so you need to find the right one and update with correct information as the current one might be outdated among other existing within a file building objects.
when in doubt - just merge, and never rebase
posted 2 months ago
Can you add or delete something in the middle of a text file at all? I thought you could overwrite the entire file or append to its end and nothing else.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database