首页 \ 问答 \ 获取LinkedHashSet的最后5个元素的子列表?(Get a sublist last 5 elements of LinkedHashSet?)

获取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中测试过。

演示: http//jsfiddle.net/Guffa/zdrP9/


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.

Demo: http://jsfiddle.net/Guffa/zdrP9/

相关问答

更多
  • 不同之处在于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执行的检查顺序。 首先,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更强大。 ...
  • 最后“System.Threading.Thread.Sleep(150);” 没有用,我注意到了一些原因 while(webBrowser1.ReadyState!= WebBrowserReadyState.Complete){Application.DoEvents(); } 在Web浏览器完全加载之前终止自身。 为了确保加载页面,我所做的是创建一个名为“wait”的bool变量。 然后我将代码更改为以下内容: wait = true; webBrowser1.Navigate("www.google ...
  • 使用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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。