What is use of hash32() in String class? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
Googling didn't help me out so I came here. What is the use of int hash32() method in String? As the name suggest it looks like for some hashing but how and where exactly it is used?

The answer is right here. Here are some choice snippets:
Java SE 7u6 introduces an improved, alternative hash function...
The alternative hash function improves the performance of these map implementations when a large number of key hash collisions are encountered.
The alternative hash function is only applied to keys of type String.
As stated by #Slanec, Java 8 made some changes to HashMap that reduced the performance drop for heavy collisions to O(lg n) instead of O(n) for Comparable keys, so there was no longer a need for alternative String hashing.

Related

regex to detect file structure in java [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I want to detect the file structure in a string.
e.g
if I have a string as /name/test/testme/2 I should be able to store it in a arraylist as different elements like {[name],[test],[testme],[2]}
String[] elements = "/name/test/testme/2".split("/");
More info can be found in the String.split() Javadoc
As Lukas pointed out, (please give him some upvoting) you should use the split method.
String[] elements = "/name/test/testme/2".split("/");
The regular expressions are not used to split strings in sections. Regular expressions are used for matching the target string with a specific generic format. In this case a boolean value indicating if the strings match is returned.
Hope I helped!

What are the orgins of the terms "parse" in java? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 9 years ago.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
This question does not appear to be about a specific programming problem, a software algorithm, or software tools primarily used by programmers. If you believe the question would be on-topic on another Stack Exchange site, you can leave a comment to explain where the question may be able to be answered.
Improve this question
In java I noticed there are methods associated with conversion of strings and those methods sometimes use the word "parse" in the name of the method. For example the static method,
static int parseInt(String str)
is used to convert a string into int. My question is this. Is "parse" short for another word? Is it just a random word or did it come from somewhere else in some other programming context in Java or anywhere else?
From wikipedia:
Parsing or syntactic analysis is the process of analysing a string of symbols, either in natural language or in computer languages, according to the rules of a formal grammar. The term parsing comes from Latin pars (ōrātiōnis), meaning part (of speech).

Object oriented programming vs. the split function... which is better? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
here is the non-oop way of doing it:
When someone presses a day on a calendar, we need to find out the day, and path. Here is the non-oop way of storing that information:
A string was created with a "-" delimiter between each piece of info we need, like this:
12-c:\files\john_doe.png
Then it was stored in an array. However, to retrieve the data, we then use the "split" function like this.
for (int t = 0;t < day_and_path.length;t++)
{
String[] day_from_db = day_and_path[t].split("-");
String day_db = day_from_db[0];
String path_db = day_from_db[1];
However the OOP way is, make a class with properties: day, path. Then store them into an array of objects.
Which way is better and why?
If you use String#split, you'll be dealing with an array of strings. If all you do is assign the strings to local variables, then there is no point in making a class for that.
If you want to hold on to the string parts and pass them around to other methods, then it begins to make sense to have an object which will conveniently encapsulate those strings.

Does Collections.sort() shuffles equal priority elements? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Or just let them alone or throws an exception?
If the third one, how can I sort elements in ArrayList saving the old order of priority equal elements?
Thanks in advance.
From the documentation:
This sort is guaranteed to be stable: equal elements will not be reordered as a result of the sort.
To save the order of the old arraylist, simply make a copy of the arraylist ahead of time. You can do this by saying:
List<Integer> oldListOrder = new ArrayList<Integer>(listToBeSorted);
Collections.sort(listToBeSorted);
Keep in mind the elements will reference the same objects in both lists. That may not affect you, it depends on what you do next.

Hash and Unhash? [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
Is it possible to Hash using bcrypt in java and again unhash it? Is it even possible? I was trying something new but I do not know anything about Unhashing (if it's possible). Can someone give me an example of somekind if it's possible?
Is there a hashing algorithm which is reversible if the key is known?
Hashing is a one-way operation by definition. You cannot retrieve source value from its cache. Actually there can be many values that produce the same hash but algorithm that translates hash to value should not exist theoretically (by definition).
If you're talking about overriding hashCode(), if your object can have more than 2^32 states then it's impossible to make any reversible hash. There are only 2^32 possible hash values (because hashCode() returns int), so only 2^32 different states can be represented.

Categories

Resources