This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static void clientCode2() { | |
Item user = findItem2("99").get(); | |
} | |
static Optional<Item> findItem2(String id) { | |
return Arrays.stream(users) | |
.filter(item -> item.id.equals(id)) | |
.findFirst(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Arrays.stream(new int[]{1,2,3,4}).anyMatch(num -> num == 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static boolean isElementExistProper(int[] ints, int b){ | |
int i=0; | |
while (true){ | |
if(ints.length==i) return false; | |
if(ints[i++]==b) return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Please do not use this | |
static boolean isElementExistUgly(int[] ints, int b){ | |
try{ | |
int i=0; | |
while (true){ | |
if(ints[i++]==b) return true; | |
} | |
} catch(ArrayIndexOutOfBoundsException ex){ | |
return false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS) | |
public class MyRequestContext { | |
private Jwt jwt; | |
public MyRequestContext(){ | |
this.jwt = (Jwt) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CallableExample { | |
public static void main(String[] args) { | |
ExecutorService executor = Executors.newFixedThreadPool(10); | |
List<Future<String>> list = new ArrayList<>(); | |
Callable<String> callable = new HelloCallable(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Main { | |
public static void main(String[] args) { | |
Thread thread1 = new Thread(new HelloRunnable()); | |
thread1.start(); | |
Thread thread2 = new Thread(new HelloThread()); | |
thread2.start(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.List; | |
import java.util.Map; | |
public class ItrExample { | |
public static void main(String[] args) { | |
List<String> list2 = List.of("item11","item22","item33"); //create a list |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public String uploadImage(MultipartFile image, String bucketName) { | |
File imageFile; | |
try { | |
imageFile = convertMultiPartToFile(image); | |
} catch (IOException e) { | |
throw new FileUploadException("Unable to convert input stream to file."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@PreAuthorize("hasRole('ROLE_USER')") | |
@RequestMapping(value = "/image/upload", method = RequestMethod.POST, produces = { "application/json", | |
"application/xml" }) | |
@ResponseBody | |
@ResponseStatus(code = HttpStatus.CREATED) | |
public ImageDto uploadImage(@RequestParam(value = "imageFile", required = true) @ValidateImg MultipartFile image) { | |
String bucketName = "public-bucket-for-files"; | |
String imageUrl = imageService.uploadImage(image, bucketName); |
NewerOlder