获取LinkedHashSet的最后5个元素的子列表?(Get a sublist last 5 elements of LinkedHashSet?)
是否有一个衬垫可以在新的LinkedHashSet中获取LinkedHashSet的最后5个元素?
这就是我目前所拥有的,但效率不高:
new LinkedHashSet<String>(new LinkedList<String>(set) .subList(Math.max(0, set.size() - 5), set.size());
或者我应该在这种情况下使用TreeSet,SortedSet,HashSet?
Is there a one liner to get the last 5 elements of a LinkedHashSet in a new LinkedHashSet?
This is what I currently have, but it's not very efficient:
new LinkedHashSet<String>(new LinkedList<String>(set) .subList(Math.max(0, set.size() - 5), set.size());
Or should I use for this case a TreeSet, SortedSet, HashSet ?
原文:https://stackoverflow.com/questions/36526324
更新时间:2023-08-08 20:08
最满意答案
使用
document.getElementById
,它工作正常:var object1 = document.getElementById('obj1'); object1.setAttribute('href','someotherURL'); alert(object1.getAttribute('href'));
在Firefox,IE和Chrome中测试过。
Use
document.getElementById
and it works fine:var object1 = document.getElementById('obj1'); object1.setAttribute('href','someotherURL'); alert(object1.getAttribute('href'));
Tested in Firefox, IE and Chrome.
相关问答
更多-
不同之处在于element.value是实时的,如果用户发生变化,比如文本框输入,它会反映出来,并显示新的值。 虽然getAttribute('value')仍然会显示原始value="whateverWasHere"值。 jsFiddle DEMO The difference is that element.value is real time and if a user changes let's say, a textbox input, it will reflect that, and show ...
-
每当有人推荐练习时,他们总是应该给出建议的合理性。 不使用getAttribute和setAttribute的原因是,IE版本至少包含8个,至少在实现这些DOM方法时存在错误。 此外,浏览器在响应使用get / setAttribute时如何更改DOM属性方面存在差异。 但是,浏览器在DOM属性方面非常一致,所以如果使用DOM属性,编写跨浏览器代码就简单多了。 唯一需要注意的是,某些浏览器不会为非标准HTML属性创建DOM属性,但它们将使用属性来设置它们。 另外一个好处是,DOM属性访问比使用函数调用get ...
-
在Python中与getattribute和setattribute混淆(Confused with getattribute and setattribute in python)[2022-06-25]
这有点复杂。 如果你请求一个对象的属性,这是Python执行的检查顺序。 首先,Python会检查对象的类是否有__getattribute__方法。 如果它没有定义,它将继承object.__getattribute__ ,它实现了查找属性值的其他方法。 下一个检查在对象的类__dict__ 。 但是,即使在那里找到了一个值,也可能不是属性查找的结果! 如果在这里找到只有“数据描述符”将优先。 最常见的数据描述符是一个property对象,它是一个函数的包装,每次访问属性时都会调用它。 您可以使用装饰器创 ... -
尝试attr功能。 $('#input').attr("value", "Value"); $('#input').attr("name", "Name"); $('#input').attr("myOwnAttribute", "Something"); Try the attr function. $('#input').attr("value", "Value"); $('#input').attr("name", "Name"); $('#input').attr("myOwnAttribute" ...
-
我能用jQuery做这个工作: $(".onoffswitch").click(function(){ if($('.onoffswitch-checkbox').is(':checked') == false) { $("#pagestyle").attr("href", "css/styles-black.css"); } else if ($('.onoffswitch-checkbox').is(':checked') == true) { $("#p ...
-
position和left不是属性,它们是样式。 width , height和id可以用作属性或样式,这就是它们在第二个示例中工作的原因。 position and left are not attributes, they are styles. width, height and id can be used as attributes or styles, which is why they work in your second example.
-
您需要将三元运算符更新为以下 (i.getAttribute('isClicked') === "true") ? i.setAttribute('isClicked', false) : i.setAttribute('isClicked', true) 因为,在属性为false的情况下, i.getAttribute('isClicked')会给出一个字符串"false" ,并将其评估为true 。 You need to update your ternary operator to f ...
-
问题在于你从each(function(d, i) { ... })调用它的方法。 你正朝着正确的方向前进: this是指你正在修改的普通html元素 。 但是,您希望调用的attr函数是d3选择的方法 - 而不是html元素。 因此,您需要将其包装在d3选择中: paths.each(function(d,i) { d3.select(this) .attr("class",""); }); 调用setAttribute有效的,因为它是普通html元素的一种方法,但显然d3的attr更强大。 ...
-
SetAttribute太慢,程序忽略InvokeMember(SetAttribute is too slow, following InvokeMember is ignored by the program)[2020-01-31]
最后“System.Threading.Thread.Sleep(150);” 没有用,我注意到了一些原因 while(webBrowser1.ReadyState!= WebBrowserReadyState.Complete){Application.DoEvents(); } 在Web浏览器完全加载之前终止自身。 为了确保加载页面,我所做的是创建一个名为“wait”的bool变量。 然后我将代码更改为以下内容: wait = true; webBrowser1.Navigate("www.google ... -
Javascript:setAttribute工作,getAttribute失败(Javascript: setAttribute works, getAttribute fails)[2022-10-04]
使用document.getElementById ,它工作正常: var object1 = document.getElementById('obj1'); object1.setAttribute('href','someotherURL'); alert(object1.getAttribute('href')); 在Firefox,IE和Chrome中测试过。 演示: http : //jsfiddle.net/Guffa/zdrP9/ Use document.getElementById a ...