This question already has answers here:
Bidirectional multi-valued map in Java
(6 answers)
Closed 9 years ago.
Is there an implementation of the following data-structure already implemented in Java:
Say I want the set for '2' ('A', 'C', 'D') but I also want the set for 'A' ('1', '2')
You have no such data structure in the Java Collections Framework.
I suggest you the guava library you may find something useful there.
Note that what you have here is essentially a undirected graph so keep an eye out for graph libraries (for example JGraphT), or write your own.
Related
This question already has an answer here:
Java equivalent for Python pool.map/ Multiprocessing
(1 answer)
Closed 4 years ago.
I know there have been questions which are similar to mine. However, they seem very outdated (assuming JDK 7, etc.)
So, I've been programming python for a while and had to learn Java for university.
I know that there is a feature in Python, where you can use a pool of Threads/Processes for mapping a list of values to a function.
from multiprocessing.dummy import Pool as ThreadPool
pool = ThreadPool(4)
results = pool.map(my_function, my_array)
I have to use the function on a large set of files and I have to use Java (10) and I want to use multiprocessing.
My question is: Does Java have such a feature? If so, whats the best practice to use it properly?
Yes, you can use parallelStream, for example, convert integer list to string list:
List<Integer> list = List.of(1, 2);
List<String> strings =
list.parallelStream()
.map(integer -> String.valueOf(integer)).collect(Collectors.toList());
This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 4 years ago.
I am reasonably experienced with programming, but not specifically in Java. I am coming across the following error when working in eclipse. My code is the following:
I have used the debug function, and it reports that carbonPrefix is pent, but that carbon stays at 0 throughout. Like I said, I am a novice to Java and Eclipse, so I may not be using the debug function to it's full extent.
For anybody that's interested, this the start of code where you input the name of an alkane and it tells you the formula. It worked in Javascript and I'm just trying to translate it into Java.
Thank you all so much!
you have to use
carbonPrefix.equals("pent");
in java == operator used to compare two object references and the method equals() is used to compare two strings to determine whether they are equal or not.
This question already has answers here:
Is there an eval() function in Java?
(14 answers)
Closed 6 years ago.
I need to write a java program which reads rules (conditions) from a file. The rules have to be transformed as conditions in Java. I don't know how to transform the rules specified as strings to Java source code.
For example, the rules like:
x != y
or
n >= 0 && s == n
should be transformed to Java source code as:
if(x != y){......}
else{....}
How can I made this possible?
May be my answer looks like a cannon against sparrow, but look at JRule the engine that allows you create flexible system of business rules inside java application
Another option is Jess. I've used it in the past with good success for handling rules-based activities.
This question already has answers here:
Java: Difference Between a collection and 'Data Structure' [closed]
(3 answers)
Closed 7 years ago.
I want to learn data structures and algorithms in java but I'm confused if collections are data structures or if there is something else . A brief explanation on data structures would help.
Thanks
Collections are data structures! Data structures are just advanced ways to hold simple data (simple being integers, strings etc.) data structures being things like Arrays, Collections.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How would I Evaluate a certain formula?
How would I split this formula into an array of characters each having their own number in the array:
a1+a2+a5*((a1+a6)*a3)
one I have added the spaces I am going to get column 1 because a1 will indicate column one and it will contain a number than I will add that to column 2. I am not allowed to use a tree or any of those other things just stacks and I have been asking that. But people keep telling me to use libraries and trees I am only in a 200 level course !
You need a grammar and a parser to do this in a general way. Something like this.