Recently shared snippets for language "Java"

Created 5 months ago by anonymous
File file = new File(path);
		
		File[] list = file.listFiles(new FilenameFilter() {
			
			@Override
			public boolean accept(File dir, String name) {
				return name.endsWith(".xlsx");
			}
			
		});
		
		if(list == null ||  list.length ==0) {
			logger.error("no .xlsx  file found in folder : " + file);
		}
Created 2 years ago by anonymous
LocalDateTime time = LocalDateTime.now();
				LocalDateTime nextHour = time.plus(1l, ChronoUnit.HOURS).truncatedTo(ChronoUnit.HOURS)
				                                .plusMinutes(60 * (time.getMinute() / 60));
				long minutes = Duration.between(LocalDateTime.now(), nextHour).toMinutes();
Created 2 years ago by anonymous
import org.apache.commons.lang3.StringUtils;
....

 List<String> filteredAndTrimmed = Arrays.asList("abc ", " cd", "", "gh").stream().map(StringUtils::trim).filter(StringUtils::isNotBlank)
			.collect(Collectors.toList());
		 
filteredAndTrimmed.forEach(System.out::println);

//output is 
abc
cd
gh
Arrays.asList(1,2,3,4).stream().mapToInt(i -> i.intValue()).sum();
Arrays.asList(1,2,3,4).stream().mapToInt(Integer::intValue).sum();
Arrays.asList(1,2,3,4).stream().collect(Collectors.summingInt(Integer::intValue));

// parallel streams
LongAdder a = new LongAdder();
Arrays.asList(1,2,3,4).parallelStream().forEach(a::add);
sum = a.intValue();


int sum = Arrays.asList(1,2,3,4).stream().reduce(0, (x,y) -> x+y)
Created 2 years ago by anonymous
private static String removeBetween(String string, String startChars, String endChars) {
		if(string.contains(startChars)&& string.contains(endChars)) {
			String substringAfter = StringUtils.substringAfterLast(string, startChars);
			String substringBefore = StringUtils.substringBefore(substringAfter, endChars);
			String finalStr = StringUtils.remove(string ,startChars + substringBefore+ endChars);
			string =removeBetween(finalStr, startChars, endChars);
		}
		return string;
	}