template.delete("list");
template.opsForList().leftPush("list", "1");
template.opsForList().leftPushAll("list", Arrays.asList("2", "3", "4"));
template.opsForList().rightPushIfPresent("list", "9");
// 此时链表中的元素从左到右依次为 :4 3 2 1 9
String i = (String) template.opsForList().index("list", 3);
System.out.println(i);
long size = template.opsForList().size("list");
System.out.println("链表长度为: " + size);
template.opsForList().set("list", 0, "6"); ///////////第一次修改可生效
//从左边弹出一个节点
String n = (String) template.opsForList().leftPop("list");
System.out.println(n);
String n1 = (String) template.opsForList().leftPop("list");
System.out.println(n1);
System.out.println(template.opsForList().rightPop("list"));
List list = template.opsForList().range("list", 0, 200);
System.out.print("链表中剩余元素为: ");
list.forEach(v -> System.out.print(v + " "));
System.out.println();
template.opsForList().set("list", 0, "7"); ////////////////第二次修改不生效
list.forEach(v -> System.out.print(v + " "));
这段代码里有两次修改链表的值,但第二次就不生效了,为什么呢?
相关分类