java remove map
map.entrySet().removeIf(e -> <boolean expression>);
java remove map
map.entrySet().removeIf(e -> <boolean expression>);
spring delete mapping
package com.zetcode.controller;
import com.zetcode.model.Post;
import com.zetcode.service.IPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import java.util.Set;
import static org.springframework.http.ResponseEntity.ok;
@Controller
@RequestMapping("/posts")
public class MyController {
@Autowired
private IPostService postService;
@GetMapping
public ResponseEntity<Set<Post>> all() {
return ok().body(postService.all());
}
@DeleteMapping("{id}")
public ResponseEntity<Long> deletePost(@PathVariable("id") Long id) {
var isRemoved = postService.delete(id);
if (!isRemoved) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
return new ResponseEntity<>(id, HttpStatus.OK);
}
}
java remove map key
/*Suppose a map*/
Map<T> map = new HashMap<>();
/*Insert 2 keys, and remove one*/
map.put('First', 'John');
map.put('Second', 'Tommy');
// Returns a value, you don't have to save it if you want
String removedValue = map.remove('First');
Removing Elements in java map
// Java program to demonstrate
// the working of Map interface
import java.util.*;
class Main {
public static void main(String args[])
{
// Initialization of a Map
// using Generics
Map<Integer, String> hashmap1= new HashMap<Integer, String>();
// Inserting the Elements
hashmap1.put(1, "Apple");
hashmap1.put(2, "Banana");
hashmap1.put(3, "Mango");
// Initial Map
System.out.println("Initial Map :"+hashmap1+"\n");
hashmap1.remove(new Integer(2));
// Final Map
System.out.println("Updated Map :"+hashmap1);
}
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us