Questions tagged [linkedhashset]

LinkedHashSet is a variant of HashSet

Fundamental:

LinkedHashSet is a variant of HashSet. Its entries are kept in a doubly-linked list. The iteration order is the order in which entries were inserted.

Null elements are allowed, and all the optional Set operations are supported.

Like HashSet, LinkedHashSet is not thread safe, so access by multiple threads must be synchronized by an external mechanism such as synchronizedSet(Set).

153 questions
0
votes
1 answer

How to create Linkedhashset using Hashset?

I was asked this question during my interview "How to create Linkedhashset using Hashset ?" anyone knows the answer ?
ACS
  • 347
  • 4
  • 9
0
votes
3 answers

Merge the files into a new big file until the number of user id's become 10 Million

I have around 100 files in a folder. Each file will have data like this and each line resembles an user id. 960904056 6624084 1096552020 750160020 1776024 211592064 1044872088 166720020 1098616092 551384052 113184096 136704072 And I am trying to…
arsenal
  • 23,366
  • 85
  • 225
  • 331
0
votes
3 answers

Why iteration time over a LinkedHashSet is not dependent on its capacity?

From the Java Docs of LinkedHashSet(LHS) class : Iteration over a LinkedHashSet requires time proportional to the size of the set, regardless of its capacity. Iteration over a HashSet is likely to be more expensive, requiring time proportional…
Geek
  • 26,489
  • 43
  • 149
  • 227
0
votes
1 answer

Hibernate all-delete-orphan for ordered collections

I have a relationship like in my Java code there was a set…
vaibhav
  • 3,929
  • 8
  • 45
  • 81
0
votes
1 answer

Change grails hasMany from LinkedHashSet to ArrayList

I have the following: class A{ static hasMany = [b: B] } Grails generates the class with property b being a LinkedHashMap. I want to configure Grails in order to generate an ArrayList instead. I know this can be done by explicitly writing the…
Tomas Romero
  • 8,418
  • 11
  • 50
  • 72
-1
votes
3 answers

Create a Return Method which accepts an int array and returns ordered and a non-duplicated int array in java

Given and int array; int[] arr = {1, 2, 5, 8, 9, 10, 20, 80, 9, 0, 100, 90, 30, 55, 22, 87, 88, 22, 33, 22, 1, 2, 3}; Requirement: requirement is: there is an array, which is without sorted and with duplicates. created a method which can accept…
UG_Coder
  • 9
  • 1
-1
votes
3 answers

How to iterate a linked hashset and compare each 2 elements in a text file in java?

I have some elements in a linked hash set.Example pencil,pen,eraser,scale First I want to access (pencil,pen) and perform some operation. Then I want to access (pencil,eraser) then (pencil,scale) and so on. I have written a code which can access 1st…
dayl fds
  • 11
  • 1
-1
votes
2 answers

Java two Set objects - hashCode() are the same but .equals() fails

I have two sets (LinkedHashSet) of a custom objects which overrides the hashCode() and equals() methods. When comparing these two sets the equal() method fails even though the hash codes are the same. …
DavidA
  • 402
  • 3
  • 12
-1
votes
1 answer

Duplicate item's index in linkedHashSet

I am adding some values to a LinkedHashSet and based on add() method's output i.e. true/false, I am performing other operations. If the Set contains duplicate element it returns false and in this case I want to know the index of the duplicate…
maximus335
  • 674
  • 1
  • 5
  • 19
-2
votes
1 answer

error using isEmpty() in linkedhashset

i'm using linkedhashset to store my synonym list. if there is synonym for my search word, some statement will be done. However, when there is no synonym for my search word, some errors will occur. Below is part of my program. String[] synset =…
syakirah ibrahim
  • 29
  • 1
  • 1
  • 8
-2
votes
2 answers

How to fetch the first element in a collection in java

My question is, How to fetch the first element in a collection in java Example : LinkedHashSet h1 = new LinkedHashSet(); h1.add("Ani","Broadway NY",10001); And I want to fetch "Ani" only How can I do this?
Anish
  • 155
  • 1
  • 13
-2
votes
2 answers

ClassCastException from LinkedHashSet to String

I want to get array of Strings out of LinkedHashSet but I get ClassCastException in line where i try to print my values in foreach loop. I get that there is something wrong with powerset method but when i tryed to fix it by adding LinkedHashSet…
Eugene Shymko
  • 173
  • 2
  • 11
-2
votes
2 answers

java.util.Arrays$ArrayList cannot be cast to java.util.LinkedHashSet

I want to write a java program that will give me frequency of letters in a given String. I have tried this: public void frequencyOfLetter() { String strMOd[] = "Hurricane.".split(""); LinkedHashSet lhs = (LinkedHashSet)…
paul
  • 4,333
  • 16
  • 71
  • 144
-2
votes
2 answers

LinkedHashSet.contains() returns true when it should return false

public class MyClass extends Activity { public static final String DEFAULT_ID = "def"; public static final LinkedHashSet DEF_IDS = new LinkedHashSet<>(Arrays.asList(DEFAULT_ID)); private boolean isDefault(String currentId) { …
kandi
  • 1,098
  • 2
  • 12
  • 24
-3
votes
3 answers

How to use HashMap as LinkedHashSet

When I run this program:- import java.util.HashMap; import java.util.LinkedHashSet; import java.util.Map; public class try1 { public static void main(String args[]) { Map props = new HashMap(); …
Vibhor Verma
  • 161
  • 1
  • 4
  • 13
1 2 3
10
11