//这里的顺序,是我自己定义的一个List<String>
        String[] regulation = {"jams","buke","rose","lua"};
        final List<String> regulationOrder = Arrays.asList(regulation);
        String[] ordered = {"rose","jams","lua","rose","buke","jams","rose","buke","jams"};
        List<String> orderedList = Arrays.asList(ordered);
        Collections.sort(orderedList, new Comparator<String>()
        {
            public int compare(String o1, String o2)
            {
                int io1 = regulationOrder.indexOf(o1);
                int io2 = regulationOrder.indexOf(o2);
                return io1 - io2;
            }
        });
        System.out.println(orderedList);

相关文章:

  • 2021-04-17
  • 2022-12-23
  • 2021-08-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-22
  • 2022-12-23
猜你喜欢
  • 2021-08-18
  • 2022-12-23
  • 2021-07-15
  • 2021-04-05
  • 2022-12-23
  • 2021-12-24
  • 2022-02-17
相关资源
相似解决方案