Solution 1 :

Not sure if I understood it right, but what about parsing the Html into a HashMap to get key-value pairs? That would get rid of duplication at least. Then you could do something like:

List<Employee> employeeById = new ArrayList<>(map.values());
Collections.sort(employeeById);

And get the results as:

[Employee{id=1, name='Mher'}, 
Employee{id=2, name='George'}, 
Employee{id=8, name='John'}, 
Employee{id=22, name='Annie'}]

Source: https://www.baeldung.com/java-hashmap-sort

Solution 2 :

Parsed the HTML and added them to a list, then created a custom Object, then two comparators to double sort the list.

    Comparator<MyObject> compareByName = Comparator
         .comparing(Article::getName);

    Comparator<MyObject> compareByName2 = Comparator
             .comparing(MyObject::getDate).reversed();

    myList.sort(compareByName.thenComparing(compareByName2));

Problem :

I have an HTML snippet that I need to change around in Java, I have been using JSOUP to parse through, but I feel like it may not be as efficient. I uploaded pictures of what I am looking for here. Sorting from date of the TD news to oldest & if there is duplicat A hrefs delete the node as a whole.
I have an arraylist of the given divs that will be included as well

ObservableList<String> names; 

Im thinking the a way could be to foreach through the list and grab from that name all the way down until a div is hit? I feel like this is a simple problem and im over thinking it, thank you for the help!

foreach(String name: names)
{}

Before example

Sorted without duplicates example

HTML(no sort with duplicates):

<div>CHTR</div>
<td width="130" align="right" style="white-space:nowrap">Mar-04-20 08:54AM&nbsp;&nbsp;</td>
</br>
<a sname='CHTR' href="https://test.com/news/why-charter-chtr-stock-might-135401270.html" target="_blank" class="tab-link-news">Why Charter (CHTR) Stock Might be a Great Pick</a></br>
<td width="130" align="right">Mar-04-20 08:53AM&nbsp;&nbsp;</td>
</br>
<a sname='CHTR' href="https://test.com/news/charter-offers-senior-unsecured-notes-135400843.html" target="_blank" class="tab-link-news">Charter Offers Senior Unsecured Notes</a>. 
</br>
<div>PEGI</div>
<td width="130" align="right" style="white-space:nowrap">Mar-04-20 12:49 PM&nbsp;&nbsp;</td>
</br>
<a sname='PEGI' href="www.test.com/news/3548648-pattern-energy-low-odds-of-competing-bid-raymond-james-says">Pattern Energy has low odds of competing bid, Raymond James says</a></br>
<div>CHTR</div>
<td width="130" align="right" style="white-space:nowrap">Mar-04-20 12:39 PM&nbsp;&nbsp;</td>
</br>
<a sname='CHTR' href="www.test.com/news/3548649-charter-offering-senior-notes">Charter offering more senior notes</a></br>
<div>PEGI</div>
<td width="130" align="right" style="white-space:nowrap">Mar-04-20 12:49 PM&nbsp;&nbsp;</td>
</br>
<a sname='PEGI' href="www.test.com/news/3548648-pattern-energy-low-odds-of-competing-bid-raymond-james-says">Pattern Energy has low odds of competing bid, Raymond James says</a></br>
<td width="130" align="right" style="white-space:nowrap">Mar-04-20 08:40 AM&nbsp;&nbsp;</td>
</br>
<a sname='PEGI' href="www.test.com/news/greatbuy">Great buy with PEGI</a></br>    

Comments

Comment posted by Matt

This HTML is invalid (

By