Relative Content

Tag Archive for javajava-stream

PrintStream or ByteArrayOutputStream are writing the same every time

Im working on this school project and decided to create a file for the business payroll.
The thing is that i have a void method that prints the payroll, and i use PrintStream and ByteArrayOutputStream to send the print of the payroll to a String that after i use to write it on a File, but every time that i check it, even when the method that prints the payroll prints different data, the files are always created with the data of the first run. What should i do?

Grouping goods of different category for maximum Discount – java

201 / 5.000
I’m currently having problems optimizing my algorithm. It’s about a shop that offers several different goods that are divided into 5 different categories (food, drinks, etc.). If you buy two goods from two different categories, you will receive a 5% discount on these two goods. If you purchase from 3 different categories you will receive a 10% discount. If you purchase from 4 different categories you will receive a 20% discount. If you purchase from 5 different categories you will receive a 25% discount.

Predicates and functions with no arguments

Considering the code given below, I am confused as to how I am able to pass anotherTest method that returns a boolean but does not accept an argument for filter in place of a Predicate and anotherTransform method for map in place of a Function.

Predicates and functions with no arguments

Considering the code given below, I am confused as to how I am able to pass anotherTest method that returns a boolean but does not accept an argument for filter in place of a Predicate and anotherTransform method for map in place of a Function.

Java predicates and function

public static void main(String[] args) { List<String> strings = Arrays.asList(“a”, “b”, “c”, “d”); strings.stream() .filter(s -> test(s, “temp”)) .map(s -> transform(s, “temp”)) .count(); } public static boolean test(String s1, String s2) { return s1.equals(s2); } public static String transform(String s1, String s2) { return s1 + s2; } Considering the code given above, I am […]