Java ASCII Art Star Rectangle
Program which print 11X11 (11 rows by 11 columns) star rectangle and also one star in the center Output:
Program which print 11X11 (11 rows by 11 columns) star rectangle and also one star in the center Output:
In this example we will make Java program that filter List with Predicate. is create with positive and negative numbers. Then this list is filter by Stream.filter method which accept predicate as argument. There are three examples: Output:
Program that convert from Map to List in several ways. There are several cases based on the desired result: Output:
Example of a Java program which convert Set to List with ArrayList’s constructor which accept Collection. Output:
This is example of java program we will see ho to convert list to set. We use List to keep order of the element which are added. On the other hand Java Set does not keep the elements in order and also does not keep duplicate elements. Our program let’s created duplicated elements and add … Read more
Let’s try to create simple Java ASCII Art as letter V. Program which create letter V with 10 columns 20 rows Output
One of the way to remove elements of collection (in this example list) is to use method removeIf Method declaration: default boolean removeIf(Predicate<? super E> filter) Description: Removes all of the elements of this collection that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller. … Read more
If you need to find difference between two sets you can use method removeAll. The difference will be kept only on the set which is calling the method. Definition: booleanremoveAll(Collection<?> c) Description: Removes from this set all of its elements that are contained in the specified collection (optional operation). If the specified collection is also a … Read more
If you need to get only the elements which are common for two sets you can use the method retainAll. The documentation for this method states: “Method signature: boolean retainAll(Collection<?> c) Description: Retains only the elements in this set that are contained in the specified collection (optional operation). In other words, removes from this set all … Read more
In this example we can see record Person and we use stream’s sorted(Comparator<? super T> comparator) method to sort the List of people by their age. So sorted(Comparator<? super T> comparator) accept as parameter Comparator. For this reason we have to create Comparator and we sort inside by age. The documentation for sorted(Comparator<? super T> comparator) state: Returns … Read more