Java Technology

Java Technology

Share

06/03/2026

Wap to check string is anagram?
package java8;

import java.util.Arrays;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class AnagramLambda {


public static void main(String[] args) {

String s1 = "geeks";
String s2 = "kseeg";

Map map1 = s1.chars()
.mapToObj(c -> (char) c)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));

Map map2 = s2.chars()
.mapToObj(c -> (char) c)
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));


System.out.println(map1.equals(map2) ? "Anagram" : "Not Anagram");



boolean isAnagram =
Arrays.equals(
s1.chars().sorted().toArray(),
s2.chars().sorted().toArray()
);

System.out.println(isAnagram ? "Anagram" : "Not Anagram");


}
}

27/09/2025

Sql Query
========================================

1. Write a query to find the second highest salary in the employees table.
SELECT MAX(SALARY)
FROM HR.EMPLOYEES
WHERE SALARY NOT IN (SELECT MAX(SALARY) FROM HR.EMPLOYEES);
2. Write a query to find the second highest salary using a < condition.
SELECT MAX(SALARY)
FROM HR.EMPLOYEES
WHERE SALARY < (SELECT MAX(SALARY) FROM HR.EMPLOYEES);
________________________________________
Aggregate Functions by Department
3. Write a query to display the maximum salary in each department.
SELECT MAX(SALARY), DEPARTMENT_ID
FROM HR.EMPLOYEES
GROUP BY DEPARTMENT_ID;
4. Write a query to display the minimum salary in each department.
SELECT MIN(SALARY), DEPARTMENT_ID
FROM HR.EMPLOYEES
GROUP BY DEPARTMENT_ID;
5. Write a query to display the number of employees in each department.
SELECT COUNT(*), DEPARTMENT_ID
FROM HR.EMPLOYEES
GROUP BY DEPARTMENT_ID;
________________________________________
Odd and Even Rows
6. Write a query to display all employees with odd-numbered rows using ROWNUM.
SELECT *
FROM (
SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, ROWNUM RN
FROM HR.EMPLOYEES ORDER BY RN
)
WHERE MOD(RN,2) != 0;
7. Write a query to display all employees with even-numbered rows using ROWNUM.
SELECT *
FROM (
SELECT EMPLOYEE_ID, FIRST_NAME, LAST_NAME, EMAIL, ROWNUM RN
FROM HR.EMPLOYEES ORDER BY RN
)
WHERE MOD(RN,2) = 0;
________________________________________
Grouping by Names
8. Write a query to display the count of each first name, ordered by frequency.
SELECT FIRST_NAME, COUNT(*)
FROM HR.EMPLOYEES
GROUP BY FIRST_NAME
ORDER BY COUNT(*);
9. Write a query to display only those first names that occur more than once.
SELECT FIRST_NAME, COUNT(*)
FROM HR.EMPLOYEES
GROUP BY FIRST_NAME
HAVING COUNT(*) > 1;
________________________________________
Pattern Matching with LIKE
10. Display the first names that start with ‘D’.
SELECT FIRST_NAME FROM HR.EMPLOYEES WHERE FIRST_NAME LIKE 'D%';
11. Display the first names that end with ‘n’.
SELECT FIRST_NAME FROM HR.EMPLOYEES WHERE FIRST_NAME LIKE '%n';
12. Display the first names that contain the letter ‘r’.
SELECT FIRST_NAME FROM HR.EMPLOYEES WHERE FIRST_NAME LIKE '%r%';
13. Display the first names that do not contain the letter ‘r’.
SELECT FIRST_NAME FROM HR.EMPLOYEES WHERE FIRST_NAME NOT LIKE '%r%';
14. Display the first names that are exactly 4 characters long.
SELECT FIRST_NAME FROM HR.EMPLOYEES WHERE FIRST_NAME LIKE '____';
15. Display the first names where the second character is ‘o’.
SELECT FIRST_NAME FROM HR.EMPLOYEES WHERE FIRST_NAME LIKE '_o%';
16. Display the first names where the fourth character is ‘m’.
SELECT FIRST_NAME FROM HR.EMPLOYEES WHERE FIRST_NAME LIKE '___m%';
17. Display the first names that contain the substring ‘ll’.
SELECT FIRST_NAME FROM HR.EMPLOYEES WHERE FIRST_NAME LIKE '%ll%';
18. Display the first names that start with ‘R’ and end with ‘l’.
SELECT FIRST_NAME FROM HR.EMPLOYEES WHERE FIRST_NAME LIKE 'R%l';
________________________________________
Filtering by Hire Date
19. Write a query to display employees hired on 17-June-2013, by formatting the hire date and using LIKE.
SELECT FIRST_NAME, HIRE_DATE
FROM HR.EMPLOYEES
WHERE TO_CHAR(HIRE_DATE, 'MM/DD/YYYY, HH:MI:SS AM') LIKE '06/17/2013%';
20. Write a query to display employees hired exactly on 17-June-2013 using TO_DATE.
SELECT FIRST_NAME, HIRE_DATE
FROM HR.EMPLOYEES
WHERE HIRE_DATE = TO_DATE('2013-06-17', 'YYYY-MM-DD');

open this link for practice.

Oracle Live SQL

Want your school to be the top-listed School/college in Delhi?
Click here to claim your Sponsored Listing.

Category

Telephone

Address


G-6/365 FF Sec-16 Rohini New Delhi
Delhi
110085