Java

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Abhishek bhalkhede

05

1) 1)add items in the map.2)remove items from int value = map.get("cherry");


the map.3)search specifickey fromthe map4)get
value of the specific key 5)insert map System.out.println("The value of the key
elementsofthe map in to other map 6)print all 'cherry' is " + value);
keys and values of the map injav injavapackage
hashSet; System.out.println(" ");
import java.util.HashMap;
System.out.println("inset map element of
import java.util.Map; one map into other map .");
public class MapExample { Map<String, Integer> map2 = new
HashMap<>();
public static void main(String[] args) {
map2.put("orange", 4);
Map<String, Integer> map = new
HashMap<>();System.out.println("add items in map2.put("pear", 5);
the map.");
map.putAll(map2);
map.put("apple", 1);
System.out.println(map2);
map.put("banana", 2);
System.out.println(" ");
map.put("cherry", 3);
System.out.println("print all keys and
System.out.println(map); values of the map");
System.out.println(" "); for (Map.Entry<String, Integer> entry :
map.entrySet()) {
System.out.println("remove items in the
map."); System.out.println("Key: " +
entry.getKey() + ", Value: " +
map.remove("banana");
entry.getValue()); }}}
System.out.println(map);
Output:
System.out.println(" ");

System.out.println("search specific keyfrom


the map.");

if (map.containsKey("apple"))

System.out.println("The map contains


the key 'apple'");

}
Abhishek bhalkhede
05

Question 2) <!DOCTYPE html>

// welcome.jsp <html>

<%@ page language="java" <head>


contentType="text/html; charset=UTF-8"
<meta charset="UTF-8">
pageEncoding="UTF-8"%>
<title>Print Date Page</title>
<!DOCTYPE html>
</head>
<html>
<body>
<head>
<%
<meta charset="UTF-8">
String name = (String)
<title>Welcome Page</title> request.getAttribute("name");

</head> out.println("Today's date is: " + new


java.util.Date());
<body>
out.println("<br>");
<h1>Welcome to my website!</h1>
out.println("Your name is: " + name);
<%
%>
String name = "abhisehk bhalkhede";
</body>
request.setAttribute("name", name);
</html>
request.getRequestDispatcher("printdate.jsp").f
orward(request, response); Output:-

%>

</body>

</html>

// printdate.jsp

<%@ page language="java"


contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>

You might also like