在linkedHashSet中有序插入,任何高效的方式?(Ordered insertion in linkedHashSet, any performant way ?)
所以我有一个LinkedHashSet,其值为a1,a2,b,c1,c2
我想用x替换b,这样x的顺序应该与b的顺序相同。
一个显而易见的方法是
private LinkedHashSet<String> orderedSubstitution(final Set<String> originalOrderedSet, final String oldItem, final String newItem) { final LinkedHashSet<String> newOrderedSet = new LinkedHashSet<String>(); // Things we do to maintain order in a linkedHashSet for (final String stringItem : originalOrderedSet) { if (stringItem.equals(oldItem)) { newOrderedSet.add(newItem); } else { newOrderedSet.add(stringItem); } } return newOrderedSet; }
不仅这是O(n)我也觉得这不是最快的方式。 更好的解决方案? 注意:我必须使用linkedHashMap。
So I have a LinkedHashSet , with values say a1, a2, , b, c1, c2
I want to replace, b with x , such that the order of x should be same as order of b.
One obvious way would be
private LinkedHashSet<String> orderedSubstitution(final Set<String> originalOrderedSet, final String oldItem, final String newItem) { final LinkedHashSet<String> newOrderedSet = new LinkedHashSet<String>(); // Things we do to maintain order in a linkedHashSet for (final String stringItem : originalOrderedSet) { if (stringItem.equals(oldItem)) { newOrderedSet.add(newItem); } else { newOrderedSet.add(stringItem); } } return newOrderedSet; }
not only this is O(n) i also feel this is not the fastest way. Any better solution ? NOTE : I HAVE TO use linkedHashMap.
原文:https://stackoverflow.com/questions/12826916
更新时间:2023-11-02 07:11
最满意答案
如果我正确理解了这个问题,您希望能够将“标题”和“Hello”作为一个项目拖动吗?
如果是这样,只需将每个项目包装在div中:
<div> <dt class="ui-state-default">Title</dt> <dd>Hello</dd> </div>
小提琴: http : //jsfiddle.net/5p2ynsLx/2/
If I understand the question correctly, you want to be able to drag the "Title" and "Hello" as one item?
If so just wrap each item in a div:
<div> <dt class="ui-state-default">Title</dt> <dd>Hello</dd> </div>
Fiddle: http://jsfiddle.net/5p2ynsLx/2/
相关问答
更多-
我想这是由你决定的语义,但在我看来: 而不是定义列表,应该使用与表单相关的属性。
-
dl { width: 100%; overflow: hidden; background: #ff0; padding: 0; margin: 0 } dt { float: left; width: 50%; /* adjust the width; make sure the total of both is 100% */ background: #cc0; padding: 0; margin: 0 } dd { f ...
-
在最基本的情况下,您可以简单地使用click事件处理程序进行toggle : // When any dt element is clicked $('dt').click(function(e){ // All dt elements after this dt element until the next dt element // Will be hidden or shown depending on it's current visibility $(this).nextU ...
-
好吧,这只是你想要的方式。 我修复了wazaminator代码,以便它可以跨浏览器使用。 问题是几个浏览器为dds添加了margin-start。 我没有在IE中测试: dt { float: left; clear: left; margin-right: 5px; font-weight: bold; } dd { margin-left: 0px; } http://jsfiddle.net/sPQmw/18/ Ok this works just the way you wa ...
-
这是一个使用弹性框,没有更改列表,只有CSS。 基本上只是使用nth-child伪选择器定义dl nth-child节点的顺序。 遗憾的是,这里使用的calc()方法取决于知道列表中的子项数(在我的例子中:4)。 只使用CSS,您无法真正确定子项的数量,但如果您知道列表中的最大项目数,则可以计算兄弟姐妹并为不同情况准备CSS: CSS能检测一个元素有多少个子元素? dl { display: flex; flex-flow: row wrap; } dt,dd { margin: ...
-
你的问题是没有生成一个空的dd并留下一个空的空间(高度:0px)。 如果可以,是的,只需简单地说 在任何空元素内。 这是跨浏览器最简单的解决方案。 一个简单,纯粹的CSS修复将是这样的: dd:after {content:"."} 但它在每个定义后添加一个点...... 您还可以在dd上设置最小高度: dt {clear: left;} dt, dd {min-height:1.5em;} (dt和dd min-height需要相同!) 演示 ...如果您的dt高度不规则(例如,如果它在2行上有时), ...
-
使用jquery删除
- 而不使用
- (Delete
- without
- with jquery)
[2022-01-25]$('dt').filter(function(){ return !($(this).next().is('dd')); }).remove(); 请在此处查看: http : //jsbin.com/isute 这也可以,但很奇怪,并且不会选择最后一个- ,所以我添加了另一个选择器: $('dt + dt').prev().add('dt:last-child').remove(); 即:选择所有
- 之后的
- , ...
-
如果我正确理解了这个问题,您希望能够将“标题”和“Hello”作为一个项目拖动吗? 如果是这样,只需将每个项目包装在div中:
- Title
- Hello
-
右边有多个DD的DT?(DT with multiple DD on the right?)[2024-03-12]
这并不难,只记得你的组合: dt { float: left; width: 8em; } dd { margin-left: 9em; } dd + dd { margin-left: 9em; } JS小提琴演示 。 参考文献: E + F ,adajacent-sibling选择器 。 This isn't that hard, just remember your combinators: dt { float: left; width: 8em ... -
使dt和dd具有相同的高度,以在dt上应用背景颜色(make dt and dd the same height to apply a background color on dt)[2023-08-23]
这里没有“简单的CSS修复”。 在这种情况下,我可能会使用一个table ,因为它看起来有点像表格数据(这使得解决问题非常容易)。 http://jsfiddle.net/UvPGG/