How to rearrange objects in arraylist based on card type [duplicate]

57
October 21, 2021, at 10:40 AM
This question already has answers here:
Collections.sort with multiple fields (14 answers)
Closed 15 hours ago.

I have a scenario where I have to rearrange the elements of bank name in a particular order. This list can be in any order [Wellsfargo, Bank of America, Chase, Citi, American Express] and may not have one or more of the banks in the list. I'm trying to think of logic to rearrange to only this order. [Chase, Citi, Bank Of America, Wellsfargo, American Express]

Any help is greatly appreciated

Answer 1

As noticed in the comments, you can sort with a custom Comparator comparing element's indexOf a List with the desired order:

private static final List<String> ORDER_LIST = List.of("Chase", "Citi", "Bank Of America", "Wellsfargo", "American Express");
public static List<String> sort(String... names) {
    return Stream.of(names)
            .sorted(Comparator.comparingInt(ORDER_LIST::indexOf))
            .collect(Collectors.toList());
}

Then you can do:

List<String> names = sort("American Express", "Citi", "Chase");
    
System.out.println(names);

Output:

[Chase, Citi, American Express]
READ ALSO
useSWRInfinite - getKey function always gets pageIndex as 1

useSWRInfinite - getKey function always gets pageIndex as 1

I am using the SWRInfinite example as defined here (https://githubcom/vercel/swr/discussions/732) and here (https://swr

45
How to get a value on a page using jquery and echo it onto the page using php

How to get a value on a page using jquery and echo it onto the page using php

Problem: I need to get the number 65 in strong tagI tried the following code, but it shows Uncaught ReferenceError

58
UPDATE unknown column in on clause

UPDATE unknown column in on clause

column sales_mode value : A|B -> 1|2

50
How do I have both &#39;Scoll Into View&#39; and &#39;2D/3D Transform&#39; when pressing on an element?

How do I have both 'Scoll Into View' and '2D/3D Transform' when pressing on an element?

Currently I have both scrolled into view and move & scale set on my elements and the scrolled into view overrode my move & scale transformsHow do I have both on my elements? When I remove scrolled into view, the move & scale worked perfectly...

46