我正在按钮单击时修复DIV元素,我可以更改我正在克隆的DIV元素的ID值.但是有可能改变内部元素的id.
在下面的代码我改变了#selection克隆时的ID ,我需要动态更改id #select.
<div id="selections">
<div class="input-group" id="selection">
<span class="input-group-addon">
<i class="icon wb-menu" aria-hidden="true"></i>
</span>
<select class="show-tick" data-plugin="select2" id="select">
<option>True</option>
<option>False</option>
</select>
</div>
</div>
<button class="btn btn-primary" type="button" style="margin-left: 30px;">
Add new selection
</button>
Run Code Online (Sandbox Code Playgroud)
JS下面
$(function() {
//on click
$("body").on("click", ".btn-primary", function() {
alert($(".input-group").length)
var
//get length of selections
length = $(".input-group").length,
//create new id
newId = "selection-" + length++,
//clone first element with new id
clone = $("#selection").clone().attr("id", newId);
//append clone on the end
$("#selections").append(clone); …Run Code Online (Sandbox Code Playgroud) 我有下表,现在我需要删除具有重复"refIDs"的行,但至少有一行与该ref,即我需要删除第4行和第5行.请帮我这个
+----+-------+--------+--+
| ID | refID | data | |
+----+-------+--------+--+
| 1 | 1023 | aaaaaa | |
| 2 | 1024 | bbbbbb | |
| 3 | 1025 | cccccc | |
| 4 | 1023 | ffffff | |
| 5 | 1023 | gggggg | |
| 6 | 1022 | rrrrrr | |
+----+-------+--------+--+
Run Code Online (Sandbox Code Playgroud) 我有一个短语,我在空白处进行分割并创建一个地图来保存该单词和该单词的索引位置。
我工作得很好。但问题是当短语包含重复的单词时。 com.google.common.collect.Multimap所以我想在Google Guava中使用。
有没有办法使用下面的流收集器生成多重贴图?
List<String> words = new ArrayList<>(Arrays.asList(phrase.split("\\s+")));
Map<String, Integer> tokenMap = IntStream.range(0, words.size())
.boxed()
.collect(Collectors.toMap(words::get, i -> i));
Run Code Online (Sandbox Code Playgroud) 是否有最简单的方法来检查字符串中是否有一年(比如4位数字),还可以找到字符串中存在4位数字的时间.
例如 "My test string with year 1996 and 2015"
产量
Has year - YES
number of times - 2
values - 1996 2015
我想做一个拆分字符串并检查每个单词,但想检查是否有任何有效的方法.
我有以下清单
[12_223,13_4356,15_5676]
我能够使用以下代码溢出下划线并将其转换为一个Hashmap
list.stream()
.map(s -> s.split("_"))
.collect(Collectors.toMap(
a -> a[0],
a -> a[1]));
Run Code Online (Sandbox Code Playgroud)
它给出了下面的地图
{"12"="223", "13"="4356", "15"="5676"}
但我想更改此代码,以便它给我一个像下面的地图列表,因为我可能会在分割时遇到重复的键
[{"12"="223"}, {"13"="4356"}, {"15"="5676"}]
我有三个字符串列表。现在我需要确保一个元素只出现在这三个列表之一中。我不想在列表中重复。您可以假设每个列表中没有重复项。
我尝试使用removeIf()及其服务于我的目的。我确定这不是最好的方法。在 Java 8+ 中有没有其他方法可以做到这一点?
列表的优先级是 list1 > list2 > list3
List<String> list1 = Stream.of("23","45","655","43","199").collect(Collectors.toList());
List<String> list2 = Stream.of("13","23","54","655","111","13").collect(Collectors.toList());
List<String> list3 = Stream.of("76","45","33","67","43","13").collect(Collectors.toList());
list2.removeIf(i->list1.contains(i));
list3.removeIf(i->list1.contains(i) || list2.contains(i));
System.out.println(list1);
System.out.println(list2);
System.out.println(list3);
Run Code Online (Sandbox Code Playgroud)
输出低于预期
[23, 45, 655, 43, 199]
[13, 54, 111, 13]
[76, 33, 67]
Run Code Online (Sandbox Code Playgroud)