DevShivmohan / Learning-everything

Learning for developer only
0 stars 1 forks source link

Java - stream [filter and map] #7

Open DevShivmohan opened 2 years ago

DevShivmohan commented 2 years ago

*_public static void main(String[] args) { List linkedList=new LinkedList<>(); for(int i=16;i<30;i++) linkedList.add(new Test(i,"Shiv"+i)); System.out.println(linkedList); // map are used to mapping these value to his value linkedList.stream().map(t1->(t1.setId(t1.getId()2))).collect(Collectors.toList()).forEach(System.out::println); // filter are used to filter the object from list List filtered= linkedList.stream().filter(t1->(t1.getId()>24 && t1.getName().equals("Shiv29"))).collect(Collectors.toList()); System.out.println(filtered); filtered.forEach(System.out::println); }_**

DevShivmohan commented 2 years ago

Getting sum of all elements

mapping List<?> List totalSize=new LinkedList<>(); totalSize.stream().mapToLong(Long::longValue).sum()

DevShivmohan commented 2 years ago

foreach for arrays as in list

private void searchFileViaSecretKey(File rootPath,CryptoSecretKeyDTO cryptoSecretKeyDTO){ File[] files=rootPath.listFiles(); Arrays.stream(files).forEach((file1 -> { if(file1.isDirectory()) searchFileViaSecretKey(rootPath,cryptoSecretKeyDTO); else if(cryptoSecretKeyDTO.getSecretKey().equals(file.getName().substring(0,36))){ this.file=file1; return; } })); }

DevShivmohan commented 1 year ago

delete directory containing files and sub-directory

FileUtils.forceDelete(new File(uri));