草庐IT

collection_list

全部标签

loop_list单向循环列表

#include"loop_list.h"//创建单向循环链表loop_pcreate_head(){   loop_pL=(loop_p)malloc(sizeof(loop_list));   if(L==NULL)   {      printf("createfail\n");      returnNULL;   }   L->len=0;   L->next=L;   returnL;}//创建节点loop_pcreate_node(datatypedata){   loop_pnew=(loop_p)malloc(sizeof(loop_list));   if(new==NUL

具有元素超时的 Java Collection 实现

是否有一些支持元素过期的集合实现。例如:CollectioncachedUsers=newExpirableList(10000);在哪里publicExpirableList(finallongtimeout){...}在给定时间后(在这个特定示例中为10000ms),添加的元素将从集合中删除。通过使用它,我们将防止我们的cachedUsers集合溢出。 最佳答案 是的,Guava支持定时过期的缓存。参见GuavaExplained'spageoncaches.另一种方法是LRU(最近最少使用)缓存,它在插入新元素时处理最早访问的

Java8 lambda : concat list

这个问题在这里已经有了答案:HowcanIturnaListofListsintoaListinJava8?(12个答案)关闭4年前。我正在尝试连接流列表并对其进行处理。classA{publicListbList;}ListaList;aList.stream().map(a->a.bList)....这里我得到了几个b的列表。但是,我想将我所有的b都收集在一个列表中。有什么想法吗?

java - 如何断言两个 List<String> 相等,忽略顺序

我正在使用AssertJ我试图断言两个List包含相同的字符串,忽略顺序。Listexpected=Arrays.asList("Something-6144-77.pdf","d-6144-77.pdf","something-6144-78.pdf","Something-6144-8068.pdf");Listactual=newArrayList();assertThat(actual.size()).isEqualTo(expected.size());//Thislinegivestheerror:"ThemethodcontainsExactlyInAnyOrder(St

java - 2个系列之间的区别? (collection1 中的元素,但不在 collection2 中)

在Java中(也许使用Guava?),是否提供了一些方法来获取两个Collection的差异,例如一个List和一个Set没有修改这些Collection之一(否则会有collection1.全部删除(集合2)?在Guava中有Sets.difference(set1,set2),但它只适用于Set,不适用于任意集合。感谢任何提示! 最佳答案 您可以使用内置的Predicate过滤第一个Collection:Collections2.filter(c1,Predicates.not(Predicates.in(c2))它适用于任何类

java - 泛型:无法从 Collections.emptyList() 转换为 List<String>

为什么publicListgetList(){if(isMyListOKReady())returnmyList;returnCollections.emptyList();}编译很好,但是对于publicListgetList(){returnisMyListReady()?myList:Collections.emptyList();}Eclipse说"Typemismatch:cannotconvertfromListtoList"? 最佳答案 您需要注意空列表的类型安全。所以像这样返回空字符串列表publicListgetL

java - 检查 List<String[]> 是否包含 String[] 的最佳方法

这个问题在这里已经有了答案:Java,returniftrimmedStringinListcontainsString(7个答案)关闭6年前。我有一个List声明为:ListarrayList=newArrayList();这List包含String的多个数组我需要检查String[]我拥有的包含在此ArrayList中.我目前正在遍历ArrayList并比较每个String[]与我正在寻找的那个:for(String[]array:arrayList){if(Arrays.equals(array,myStringArray)){returntrue;}}returnfalse;有

java - 如何根据 Collection 值的大小对 Map 进行排序?

我有一个像这样的HashMap:Map>map=newHashMap();map.put("USA",Arrays.asList("CA","IA","IL"));map.put("India",Arrays.asList("MUM","CAL"));map.put("Canada",Arrays.asList("TOR"));我想根据列表值的大小对map进行升序排序。我该怎么做?在这种情况下,我想订购加拿大、印度、美国的key。 最佳答案 HashMap没有保证的迭代顺序,因此您需要收集到LinkedHashMap为了使排序有意义

java - 如何从 List<Object> (Java) 获取数据?

我是Java新手,在显示对象列表中的数据时遇到问题。我有一个简单的方法,它应该跨多个表收集数据并将其返回给我的Controller:publicListgetHouseInfo(){Queryq=em.createNativeQuery("SELECThouses.id,addresses.country,addresses.region,house_details.rooms,house_details.squareFROMhouses,addresses,house_details");ListmyList=q.getResultList();returnmyList;}现在我想在

c# - 面试题: remove duplicates from an unsorted linked list

我正在阅读CrackingtheCodingInterview,FourthEdition:150ProgrammingInterviewQuestionsandSolutions我正在尝试解决以下问题:2.1Writecodetoremoveduplicatesfromanunsortedlinkedlist.FOLLOWUP:Howwouldyousolvethisproblemifatemporarybufferisnotallowed?我正在用C#解决它,所以我制作了自己的Node类:publicclassNodewhereT:class{publicNodeNext{get;