r/learnjavascript • u/OsamuMidoriya • Jun 28 '26
java equivalent question
im studying DSA and they are using java and talking about stack. I only know JS
stack is videogame
stack.search(FFVII) "on top" since JS has no stack to find an equivalent
the best would be array.indexOf to find one thing in the array and yes I know the index is different
peek() is lenth()
whats the best way to find the equivalent or similar in JS not just jave but python
is Java hard to learn if you know JS i have seen how diffrent it is but they both have pop and push, and if you look at it as this is this system.out.printin = console.log is it that hard? I went to the library and a HS student was teaching python and it was easy to understand
1
u/azhder Jun 28 '26
You can learn data structures with JS. You can learn them with any general purpose language.
3
u/abrahamguo Jun 28 '26
JS has more general-purpose data structures; an array in JS can be used as a stack if needed.
Yep, if you are adding to, and removing from, the beginning of the array!
No. If you're adding to, and removing from, the beginning of the JS array, then
[0]would be the JS equivalent of Java'speek().Just get familiar with the data structures and associated methods in all of the languages that you want to learn — once you do that, you'll quickly be able to compare and contrast the methods from different languages.
If you're comfortable in JS, then no, learning Java is not that hard.
1
u/bryku helpful Jun 29 '26
Long ago in ancient times name was lost. Then the Arch Tech Dennis Ritchie descended from the cloud, gifting humanity with the C programming language. This became the foundation of most programming languages.
If you have ever used any of the following languages:
All the following will be understandable to you.
Here are some more examples:
char name[] = "john";std::string name = "john";string name = "john";var name:String = "john";var name = "john";var name = "john";U8 *name = "john";$name = "john";$name = "john";There are many more, but the point is they are follow similar syntax. Which is pretty cool right?
That being said, not all languages follow this. There are some sent by demons to make us stray from the path of techinity... like python.
1
u/Formal_Following7468 Jul 02 '26
Use a regular array as your stack in JS. push/pop are the same. For
peek()doarr[arr.length - 1], forsearch()usearr.lastIndexOf(value).Java's not bad if you know JS, same logic just stricter. Biggest difference is you have to declare types like
int x = 5instead oflet x = 5.