Java String from List stringListEquals(List left, List right)

Here you can find the source of stringListEquals(List left, List right)

Description

Tests if two arrays of strings have the same members irrespective of order.

License

Open Source License

Parameter

Parameter Description
left the left
right the right

Return

the result

Declaration

public static boolean stringListEquals(List<String> left,
        List<String> right) 

Method Source Code

//package com.java2s;
/**//  ww  w  .  j  a v a 2s.com
 * Licensed under Apache License v2. See LICENSE for more information.
 */

import java.util.ArrayList;

import java.util.Collections;

import java.util.List;

public class Main {
    /**
     * Tests if two arrays of strings have the same members irrespective of order.
     * 
     * @param left the left
     * @param right the right
     * @return the result
     */
    public static boolean stringListEquals(List<String> left,
            List<String> right) {
        if (left.size() != right.size()) {
            return false;
        }
        if (left.size() == 0) {
            return true;
        }
        List<String> copyOfLeft = new ArrayList<String>(left);
        List<String> copyOfRight = new ArrayList<String>(right);
        Collections.sort(copyOfLeft);
        Collections.sort(copyOfRight);
        for (int i = 0; i < left.size(); i++) {
            if (!copyOfLeft.get(i).equals(copyOfRight.get(i))) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. stringify(List entries)
  2. stringifyList(List items)
  3. stringList(String prefix, String suffix, String separator, Object... objects)
  4. stringList2String(final String suffix, final List list)
  5. stringList2String(List list, String separator)
  6. stringListString(List list)
  7. stringListToArray(final List list)
  8. stringListToArray(List list)
  9. stringListToArray(List params)