gpt4 book ai didi

coldfusion - 如何比较两个列表元素?

转载 作者:行者123 更新时间:2023-12-01 08:26:26 25 4
gpt4 key购买 nike

我有两个 list

<cfset thelist1 = valueList(Gettest.full_name) /> 
<cfset thelist2 =ReplaceNoCase(colorList2,".jpg","","all")>

thelist1 =(test1,test2,test3,test4,test5)
thelist2 = (test1,test3)

如何将list1与list2进行比较并从list1中获取不在list2中的元素?

我在想也许要获得不在 thelist2 上的列表,我必须创建另一个 thelist3。

最佳答案

我会使用一些 java 方法来做到这一点。这是我所做的:

<cfset theArray1 = listToArray(thelist1)>
<cfset theArray2= listToArray(thelist2)>

现在如果我想保留匹配的项目,那么我会做这样的事情:
<cfset theArray1.retainAll(theArray2) />

如果我想删除匹配的项目,那么像这样的事情:
<cfset thearray1.removeAll(theArrar2) />

然后最后我将数组转换为列表(如果需要)。

注意 removeAllretainAll 是 java 方法,但在 ColdFusion 中工作正常,您甚至不需要导入 java 库或包。

关于coldfusion - 如何比较两个列表元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33701806/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com