How to achieve abstraction ?
Ans :- we can achieve abstraction by using abstract classes and Interfaces. Abstraction in java can be achieved in two ways:
Ans :- we can achieve abstraction by using abstract classes and Interfaces. Abstraction in java can be achieved in two ways:
Ans :- JDK :- JDK stands for “Java Development Kit” and which is the collection of the following : – 1. JavaCompiler 2.JVM 3.Java Library JRE :- JRE stands for “Java Runtime environment” which is the collection of JVM and …
Like if we have – a=20; b=30; I want a=30; and b=20; SOLUTION :- package p1; public class SwapNumbers { }
SOLUTION :- package mv; import java.util.ArrayList;import java.util.Collections;import java.util.List; public class AscendingAndDescendingIntegers { }
Ans:- flatMap() :- flatMap() transform each element and flattern the resulting collection into a single combined collection. Example of flatMap():- package v1;import java.util.ArrayList; import java.util.Arrays; import java.util.List;import java.util.stream.Collectors; public class FlatMapExample {public static void main(String[] args) { List<List<Integer>> list=new ArrayList<>(); …
Solution :- we will use Map to find Count of element using stream package p2; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class CountOfElement { public static void main(String[] args) { List<Integer> list=Arrays.asList(1,1,2,3,3,5,5,7,8,9,9); Map<Integer,Long> map=list.stream().collect(Collectors.groupingBy(i->i,Collectors.counting())); System.out.println(map); map=map.entrySet().stream().filter(e->e.getValue()>1).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); …
SOLUTION :- package p3; public class ArrayTwoDigitCount { public static void main(String[] args) { int[] abc= {2,1,3,44,52,23}; for(int i: abc) { if(i>=10 && i<=99) { System.out.println(“Two-digit-elements :”+i); } } } } ****************************************************************
Ans :- the main difference between Collection and Collections :- 1.Collection<E> 2.Collections 1.Collection<E> => Collection <E> is an interface from java.util package and which is the root of Java Collection<E> Framework. 2.Collections : => “Collections” is a Class from java.util …
What is the Difference between Collection and Collections ? Read more »
In Java ArrayList and Vector classes both are implements List Interface, and both are using resizable and growable Array for internal data structure. Differences with respect to : Methods: Thread Safety: Performance: Legacy: Increment Size:
Solution :- import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class DuplicateElement { public static void main(String[] args) { List<Integer> list=Arrays.asList(1,1,2,3,3,3,5); list=list.stream().distinct().collect(Collectors.toList()); System.out.println(list); } } *****************************************************