D
D
DIRR1172020-06-11 12:18:25
Java
DIRR117, 2020-06-11 12:18:25

How to display the repeating element of the list only 1 time?

Started learning Java. Now I am writing a small project. There was a problem. The bottom line is this:
you need to display the ArrayList element only 1 time.
ArrayList contains numbers: {1,3,5,4,5,1,2,3}
So you need to display element 1 only 1 time, then 3 only 1 time and so on.
The option to remove extra, repeating characters is not suitable, because this ArrayList is "connected" to another, and the lines I need are stored there.
I tried to count the number of repeated elements of Collection.frequency, in principle there is a result, but I don’t know how to draw a conclusion only 1 time. Tried with a do..while. loop, but no output of text from another ArrayList happens.

Code:

arrayExercise.add(index, new ExerciseArray(name, touch, count, day));
Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file, false), "cp1251"));
List tempList = new ArrayList<>();
int freq = 0;
for(int i=0; i tempList.add(arrayExercise.get(i).getDay());
freq = Collections.frequency(tempList, arrayExercise.get(i).getDay());
// System.out. println(s);
do{
writer.write("Element: " + arrayExercise.get(i).getDay() + System.getProperty("line.separator"));
writer.write("Text1: "+arrayExercise. get(i).getName()+", Text2: "+arrayExercise.get(i).getTouch()+" x "+arrayExercise.get(i).getCount()+System.
} while (freq<0);
if(freq>1){
writer.write("Text1: "+arrayExercise.get(i).getName()+", Text1: "+arrayExercise.get(i).getTouch()+" x "+arrayExercise. get(i).getCount()+System.getProperty("line.separator"));
continue;
}
}


arrayExercise - a sheet with objects that stores information about elements
5ee1f69c7128d814661295.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DDwrt100, 2020-06-11
@DIRR117

try shifting the elements to set , and then output the elements of the set.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question