Tag: java

58 votes
17 answers
369 views
JavaScript hashmap equivalent

As made clear in update 3 on this answer, this notation: var hash = {}; hash[X] does not actually hash the ob

avatar
Tana
0 1 0 9
asked 07 September, 2021
56 votes
26 answers
1.7K views
How to detect a loop in a linked list?

Say you have a linked list structure in Java. It's made up of Nodes: class Node { Node next; //

avatar
Shantay
0 1 0 9
asked 07 September, 2021
50 votes
24 answers
691 views
How to implement a tree data-structure in Java?

Is there any standard Java library class to represent a tree in Java? Specifically I need to represent the fo

avatar
Chaya
0 1 0 9
asked 07 September, 2021
65 votes
5 answers
1.7K views
59 votes
30 answers
1.5K views
Simplest code for array intersection in javascript

What's the simplest, library-free code for implementing array intersections in javascript? I want to writ

avatar
Clarice
0 1 0 9
asked 07 September, 2021
53 votes
27 answers
1.2K views
How do you implement a Stack and a Queue in JavaScript?

What is the best way to implement a Stack and a Queue in JavaScript? I'm looking to do the shunting-yard

avatar
Tuan
0 1 0 9
asked 07 September, 2021
55 votes
20 answers
415 views
Can I hide the HTML5 number input’s spin box?

Is there a consistent way across browsers to hide the new spin boxes that some browsers (such as Chrome) rende

avatar
Tana
0 1 0 9
asked 07 September, 2021
55 votes
12 answers
771 views
Why don't self-closing script elements work?

What is the reason browsers do not correctly recognize: <script src="foobar.js" /> <!-- self-closing

avatar
Xavier
0 1 0 9
asked 07 September, 2021
51 votes
29 answers
2.2K views
Retrieve the position (X,Y) of an HTML element relative to the browser window

I want to know how to get the X and Y position of HTML elements such as img and div in JavaScript relative to

avatar
Carmelina
0 1 0 9
asked 07 September, 2021
55 votes
20 answers
1.5K views
How do I modify the URL without reloading the page?

Is there a way I can modify the URL of the current page without reloading the page? I would like to access th

avatar
Sydney
0 1 0 9
asked 07 September, 2021
56 votes
23 answers
2K views
Storing Objects in HTML5 localStorage

I'd like to store a JavaScript object in HTML5 localStorage, but my object is apparently being converted

avatar
Santiago
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
517 views
How can I convert a stack trace to a string?

What is the easiest way to convert the result of Throwable.getStackTrace() to a string that depicts the stackt

avatar
Lashawna
0 1 0 9
asked 07 September, 2021
53 votes
30 answers
1.9K views
What does "Could not find or load main class" mean?

A common problem that new Java developers experience is that their programs fail to run with the error message

avatar
Xavier
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
681 views
How do I create a Java string from the contents of a file?

I've been using the idiom below for some time now. And it seems to be the most wide-spread, at least on t

avatar
Vi
0 1 0 9
asked 07 September, 2021
55 votes
30 answers
1.8K views
How to fix java.lang.UnsupportedClassVersionError: Unsupported major.minor version

I am trying to use Notepad++ as my all-in-one tool edit, run, compile, etc. I have JRE installed, and I have

avatar
Trudy
0 1 0 9
asked 07 September, 2021
56 votes
30 answers
2K views
Difference between StringBuilder and StringBuffer

What is the main difference between StringBuffer and StringBuilder? Is there any performance issues when decid

avatar
Santiago
0 1 0 9
asked 07 September, 2021
60 votes
30 answers
1.3K views
Why use getters and setters/accessors?

What's the advantage of using getters and setters - that only get and set - instead of simply using publi

avatar
Shantay
0 1 0 9
asked 07 September, 2021
64 votes
30 answers
833 views
How can I avoid Java code in JSP files, using JSP 2?

I'm new to Java EE and I know that something like the following three lines <%= x+1 %> <%= reque

avatar
Solomon
0 1 0 9
asked 07 September, 2021
51 votes
30 answers
701 views
Sort a Map<Key, Value> by values

I am relatively new to Java, and often find that I need to sort a Map<Key, Value> on the values. Since

avatar
Adolfo
0 1 0 9
asked 07 September, 2021
51 votes
30 answers
1.1K views
How to split a string in Java

I have a string, "004-034556", that I want to split into two strings: string1="004"; string2="034556"; That

avatar
Brianne
0 1 0 9
asked 07 September, 2021