All Questions
60 questions
0
votes
0
answers
79
views
Compare a HashSet<string> with an array of strings in LINQ?
I have a List called LabelFilter. Label has a Name field which is just a string such as "Test1" or "Test2" ect. I can easily convert this list into an Array of type string or a ...
-2
votes
1
answer
76
views
Which is faster? Concat 2 string then hashset contain or doing 2 hashset contains
I'm writing a high throughput java application and need your help settle a debate.
The application process strings at a very high frequency and I need to be able to check if the input contains a ...
-2
votes
1
answer
59
views
How does `new Dictionary<string, obj>(StringComparer.CurrentCultureIgnoreCase)`/`new HashSet<string>(StringComparer.CurrentCultureIgnoreCase)` work? [duplicate]
I was looking around for a way to have a dictionary key/hash set string be case insensitive. I found many answers around on SO and even on the MS website.
From what I've seen, it seems like the ...
1
vote
1
answer
110
views
ArrayIndexOutOfBoundsException after splitting a string
I am getting the following error when trying to submit this code to hackerrank on https://www.hackerrank.com/challenges/contacts/problem:
Exception in thread "main" java.lang....
2
votes
2
answers
1k
views
Time Complexity of checking whether a string is present in a HashSet Java
In a nutshell, I am confused whether the time complexity of checking whether a String exists in a HashSet is O(1) or O(m), m being the length of the longest string being checked.
I understand that the ...
0
votes
2
answers
6k
views
Convert String to HashSet in Java
I am interested in converting a string to a HashSet of charcters, But HashSet takes in a collection in the constructor. I tried
HashSet<Character> result = new HashSet<Character>(Arrays....
6
votes
1
answer
3k
views
How do I extend a HashSet<String> with another HashSet<String>?
When I try to extend a HashSet<String> with another HashSet<String>:
use std::collections::HashSet;
let mut a = HashSet::new();
a.insert("foo".to_owned());
let mut b = HashSet::...
0
votes
2
answers
2k
views
Iterating through a HashSet using a for loop
I have a HashSet that I would like to iterate through a for loop and display its contents but I don't know how to make it work. I can't seem to find a way to access an element of a certain index(i) of ...
0
votes
2
answers
349
views
HashSet of Strings and retrieval of only the first word of each element
If I have a HashSet<String>, how can I retrieve only the first word of each element of the Set?
-2
votes
1
answer
3k
views
How to convert all String's to lower case in a collection of type HashSet <String>? [duplicate]
I am not sure of best way to convert all Strings in a collection to lowercase. Any thoughts?
private Set<String> email;
if(userEmail instanceof Collection) {
this.email = new ...
1
vote
2
answers
2k
views
Why java Set.contains() is faster than String.contains()?
For a problem to find common characters between 2 strings, at first I used the straight forward String.contains() method:
static String twoStrings(String s1, String s2) {
boolean subStringFound =...
2
votes
2
answers
256
views
HashSet iterator checking letters
I have a String hashset (called "names") and I want to remove from it all the Strings that contains at least one char that isn't a capital letter.
I wrote this code and it doesn't work:
Iterator<...
0
votes
2
answers
364
views
Find the intersection of two strings in which characters appearing in both strings are returned (same sequence order as 1st String)
I am using HashMap() for the problem but am facing issues with regards to order and occurrence of characters in output.
I tried to reverse the String builder both while iteration and after ...
1
vote
5
answers
1k
views
Pangram using hashset in java
i am trying to determine whether the string is pangram or not by using set in Java
I've tried the below code.Now the output is showing as not pangram but it should be a pangram. Pls tell me whats ...
0
votes
2
answers
156
views
Returning String of joined certain fields from objects in HashSet
I'm trying to write getter for a HashSet, where Object contains multiple attributes of Strings and Integers.
Getter should return joined String of only two of the String fields, separated with coma, ...
0
votes
2
answers
38
views
Hash Set giving error when comparing an input
Trying to check a password against values in a hash set. The error appears to be in the myset.contains but cant see why.
Set<String> myset = new HashSet<>();
myset.add("Apples");
myset....
-2
votes
1
answer
600
views
Length of Longest Substring for String using HashSet
I have got the code for the length of longest substring but i am not sure what the "else" part of the below code does.
Also, what does the variable start here indicate??
while(start < i &&...
0
votes
1
answer
187
views
HashMap<HashSet, Long> comparing strings in hashset and dividing them
I'm posting the code for the following task.
I have a hashmap with entries like so:
HashMap<HashSet<String>, Long> mapping = new HashMap<>();
aaa.bb.cc.d, aaa.bb.cc, gg.hh.ee, ...
2
votes
5
answers
963
views
How to count and sort repeating strings
i have got a string of names
String str = "A. Walker, L. Gordon, C. Riley, L. Gordon";
I need to count name occurancies and sort the occurancies from biggest to lowest.
I have done the countung ...
2
votes
1
answer
2k
views
Performance: JAVA permutation
So, I had this code to generate permutations of a word, and store it to a HashSet for later comparing with a dictionary.
But when the input word has 10 or more letters, the permutation process becomes ...
0
votes
2
answers
547
views
Selecting the 2nd word in a hashset and converting it to a String? Java
I'm making a text based RPG where I want to implement a universal command "use" which will activate the effect of an item (equip weapons / drink potions / launch fireworks). All these things are ready ...
0
votes
1
answer
2k
views
C# string size in working memory
Situation :
On a 64x .NET build I store approx 50 million string in a Hashset and my RAM goes from 1.5Gb to 7.5Gb .
2 Questions :
Looking at the 6 Gb (7.5-1.5) RAM taken by the strings ... I am ...
7
votes
1
answer
4k
views
How do I pass a string to HashSet contains?
I want to use a HashSet for quick string lookup, but I can't seem to find a way to pass a string variable to contains without a compiler error.
refs = HashSet::new();
let first_pass = link_regex....
0
votes
3
answers
154
views
How to check and count if a word in a linkedHashset appears in a sentence from an arraylist?
I have been stuck on this problem for a few days. I want to be able to check and count if each word from uniqueBagOfWords appears in a sentence for example,
UniqueBagOfWords = [i, like, to, play, ...
0
votes
1
answer
134
views
Thread-safety of java HashSet in an apache tomcat servlet
I'm trying to write a multi-threaded apache tomcat servlet which will receive large quantities of text in each POST body it processes and upon a GET request, it will return the number of unique words ...
2
votes
2
answers
314
views
Java Hashset returns false instead of true
This block of code keeps returning false, and I can't figure out why.
List<String> angry = new ArrayList<String>();
while ((anger = angerSt.readLine()) != null) {
angry.add(anger);
}
...
0
votes
1
answer
74
views
String not returning any value
I am trying to encode a 15 bit binary sequence into one of the permutations in {0, 1, 2...7}. For example, any 15 bit random sequence like '001010101000101' will be encoded to one of the permutation ...
-1
votes
1
answer
2k
views
java.lang.Object[] cannot be converted to java.lang.String[] [closed]
I am new to Java. I have a HashSet of String and I am trying to convert the contains into a String[]. I follow the solution here Converting from HashSet<String> to String[]
But still got error. ...
1
vote
3
answers
137
views
Java hashset of strings or objects comparision
I developed a Java module that checks if any component on a JFrame form has changed its value(text) and puts the component it into a HashSet for the JFrame.
Currently, I put the component name(...
0
votes
1
answer
81
views
Working with 2 String Sets (Combining them)
I have 2 Set<String> with the same amount on Strings in my OnCreate(), one Set<String> holds messages from multiple users while the other one holds names of those users. I want to join ...
0
votes
1
answer
390
views
Ordering of Strings returned from Json path query and used in a Junit Assertion
Something of a newbie question:
I have to assert against an address on a page. I am querying the API firstly to get the address and I am then asserting against it on the webpage.
Here is my ...
1
vote
1
answer
527
views
maximum number of elements which can be added to an arraylist
Question :-
You're given a string S of N characters. It's known that the string consists of lowercase latin letters. The string is generated randomly. That means that every symbol is chosen randomly ...
14
votes
4
answers
2k
views
On string interning and alternatives
I have a large file which, in essence contains data like:
Netherlands,Noord-holland,Amsterdam,FooStreet,1,...,...
Netherlands,Noord-holland,Amsterdam,FooStreet,2,...,...
Netherlands,Noord-holland,...
2
votes
6
answers
26k
views
Remove element from HashSet
First of all add the element in HashSet and prints the size of HashSet which returns as expected. but i modified one of the object value and again store in to HashSet and remove the object using ...
0
votes
1
answer
144
views
Java How to Use Hashset Add String with Period when Reading from File
I'm reading a file in using a basic FileReader with a Buffer, and sorting the results into different HashSets based on with they have a period in them or not.
Later in my program I compare strings to ...
-4
votes
2
answers
895
views
How to convert from String [] [] to hashset in java?
I have multidimensional data in String[][] format. How do I conver to hashset?
I defined hashset as
HashSet students = new HashSet();
How do I convert data[][] to students?
0
votes
0
answers
50
views
Hashsets and size method [duplicate]
Well I have a hashset of strings and I want to use size()
the problem is i dont know if hashsets size can be bigger then 2,147,483,647
and if i can get their size using bigint not int "so i wont be ...
-1
votes
2
answers
57
views
How to search through two list members?
I have the following class:
public class fixFirstDuplicate
{
public string firstParam { get; set; }
public string secondParam { get; set; }
}
and the list:
public ...
0
votes
5
answers
510
views
Java : Searching Ids from hashset or String
I have large number of IDs which can I store in HashSet or String
i.e.
String strIds=",1,2,3,4,5,6,7,8,.,.,.,.,.,.,.,1000,";
Or
HashSet<String> setOfids = new HashSet<String>();
...
-2
votes
2
answers
1k
views
Java-Hashset-checking whether a given string is substring of some element
I am storing few elements in hashset in Java, suppose "hello world" ,"small elephant" , "hellostack", "others". Now, I have string suppose "hello", which I want to check whether it is substring of ...
0
votes
1
answer
906
views
trim() method do not remove white spaces in front of the text?
Please have a look at the below code
while (reader.hasNext())
{
JsonParser _parser = new JsonParser();
JsonElement jsonElement = _parser.parse(reader);
...
4
votes
2
answers
1k
views
Using Hashsets to Count Amount of Strings in Array without Duplicates
I am trying to use a hashset to count the amount of strings in a string array without counting duplicates. However, this program is not working correctly. For eg. this code prints out "4", when in ...
1
vote
2
answers
5k
views
How to know if two String are equals(uppercase and Lowercase)-Java [closed]
I am creating a program in Java with TreeSet<Object> and HashSet<Objcet> and I want to add some strings to these sets, but I have a problem:
When I add the strings, e.g I add "Brian", "...
0
votes
1
answer
438
views
How to correctly pass/add Strings from HashSet<String> in another, HashSet<String>?
I have the following problem:
I am parsing a column from a voluminous tab separated values files ("original file") in a hashSet depending on various parameters.
I want to parse it once, and write it ...
2
votes
4
answers
564
views
Java HashSet shows list in weird order, always starting with 3
I have array of Strings which actually in nothing but list of integers coming from file. I converted it to HashSet so as to remove duplicates as follows:
Set<String> intSet = new HashSet<...
1
vote
3
answers
1k
views
Searching Scrabble dictionary for word with a blank tile (" ") character
Let's say I have a String called s that represents a move on a Scrabble board: "AARDV RK"
I have a HashSet<String> called dict that contains the entire Scrabble Dictionary (~180,000 words!).
...
2
votes
3
answers
2k
views
Determine if HashSet<String> contains a different cased string
I have a large set of strings, including many duplicates. It is important that all of the duplicates have the same casing. So this set would fail the test:
String[] strings = new String[] { "a", "A", ...
0
votes
1
answer
163
views
java string and hashset-membership matching
I am converting single Chinese characters into roman letters(pinyin) using package pinyin4j in java. However, this will often yield multiple pinyins for one character(same character has different ...
2
votes
2
answers
269
views
Fastest way to check if a always changing set of strings contains a string
Here's what I'm doing:
Take a string
Check if HashSet contains the string
If it doesn't, add the string to the HashSet (if it does, do something else)
This must work with a very large arrays of ...
5
votes
4
answers
14k
views
Howto save HashSet<String> to .txt?
I want to store the HashSet to the server directory.
But i'm now only been able to store it in .bin files.
But how do I print all the Key's in the HashSet to a .txt file?
static Set<String> ...