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
3
votes
1 answer

How to remove duplicates from list without reordering in java?

I am trying to remove duplicates from my List object of the type String using Set Interface but the problem i face is that it also reorders my list which is something i don't want. I want to preserver the order of the list and remove duplicates only…
dev_marshell08
  • 1,051
  • 3
  • 18
  • 40
3
votes
4 answers

Read the files in a folder and then store each user id in a linkedhashset

I have around 100 files in a folder. And I am trying to read all those files one by one. Each file will have data like this and each line resembles an user…
arsenal
  • 23,366
  • 85
  • 225
  • 331
3
votes
1 answer

Converting custom ArrayList to LinkedHashSet

I have a custom ArrayAdapter which holds a list of events. There are duplicate values in the List, so I'm trying to put the values of List to LinkedHashSet but this displays a blank page. How do I convert custom…
input
  • 7,503
  • 25
  • 93
  • 150
3
votes
1 answer

JTable - Boolean to show as check box and must be editable

Ok so I have a JTable that I populated from an LinkedHashSet of Books. public static void LibToArray(){ rowData = new Object[Book.bookList.size()][5]; int i = 0; Iterator it = Book.bookList.iterator(); while(it.hasNext()){ …
user1808348
  • 79
  • 1
  • 1
  • 4
2
votes
3 answers

Why isn't my Java LinkedHashSet removing an object it contains?

I have an object in a LinkedHashSet that implements equals, hashCode and compareTo (in a superclass) but when I try to remove that exact object from the set set.remove(obj) the remove method returns false and the object remains in the set. Is the…
mekazu
  • 2,545
  • 3
  • 23
  • 21
2
votes
1 answer

Create a Map of Array of Structs in golang?

I had a Json of format { ..., "tclist":[{ "tcID":"TC1", "tcp":"/home/1.py", "time":"20:00:40" }, { "tcID":"TC2", "tcp":"/home/1.py", "time":"048:50:06" }], ... } I want to create…
2
votes
3 answers

Implementing a Bag in Java

I'm implementing a bag of Integers in java and I'm not sure how to do so. I would like to do so with either a HashMap, LinkedHashMap, TreeMap, TreeSet, or HashSet. Some of the things I'd like to do are Be able to count the number of occurrences of…
emmynaki
  • 157
  • 2
  • 10
2
votes
3 answers

returning a linkedhashset to xpage as multivalue

In a my applications I have defined a property of an object as a LinkedHashSet. The property I fill with values from a multi-value field: Vector ctrs = doc.getItemValue("countries"); LinkedHashSet items = new…
Malin
  • 697
  • 5
  • 21
2
votes
1 answer

set.addAll(myArrayList) doesn't add the items of list in the same order

Can't figure it out why set.addAll is adding my list with the orders switched. (still my set is declared as LinkedHashSet) The code is about getting a Set-List from SharedPreferences, convert it into an ArrayList, add one item to list and then add…
Vlad.mir
  • 685
  • 1
  • 10
  • 28
2
votes
1 answer

How can you implement LFU cache using simplest and minimum data structures.?

I was asked this question in an interview where he asked first about the difference between LRU and LFU and then asked to implement both. I knew LRU can be implemented through LinkedHashMap but I got confused with LFU. Can anyone tell me how to…
dgupta3091
  • 1,067
  • 1
  • 7
  • 18
2
votes
1 answer

LinkedHashSet fails to remove duplicate sentences from an ArrayList

I'm building an android/Java program which reads from a text file and store each sentence in the text file in an array list. Then it checks the occurrence of each word in the sentence and print out all the sentences that contains repeated…
2
votes
2 answers

LinkedHashSet and subList, getting n of collection

I am trying to do a homework in math which is find a subset of collection {1,2,..,n} where n is a number given in the code, I cannot get it done with the sublist so I need to get your help with a math programming. For example for n =…
WinterTime
  • 173
  • 2
  • 14
2
votes
2 answers

Listview with custom adapter overwriting data from my post

I am new to Java and Android. I am using a custom adapter to fill my list_view, but then got overwritten, and I don't know what I should do. By searching on the web I found something about "linkedhashset", but I don't know how to use it. Adapter…
Thiago Belão
  • 114
  • 1
  • 9
2
votes
1 answer

Java HashSet Implementation design

Editing the question to remove my analogy and ask directly. JDK HashSet implementation is like below: public class HashSet { private HashMap map; public HashSet(int capacity) { map = new HashMap(capacity); } public HashSet(int capacity,…
vsnyc
  • 2,117
  • 22
  • 35
2
votes
4 answers

What is the main difference between Hashset, Treeset and LinkedHashset, Hashmap and how does it work in Java?

I just understand that LinkedHashSet does not allows duplicate elements when it is inserting. But, I dont understand how does Hashset works in Hava? I know a bit that Hashtable is used in Hashset so the hashtable used to store the elements and here…
Achiever
  • 1,626
  • 10
  • 30
  • 54
1 2
3
10 11