Java – How to search a string in a List?

In Java, we can combine a normal loop and .contains(), .startsWith() or .matches() to search for a string in ArrayList. JavaExample1.java package com.mkyong.test; import java.util.ArrayList; import java.util.List; public class JavaExample1 { public static void main(String[] args) { List<String> list = new ArrayList<>(); list.add("Java"); list.add("Kotlin"); list.add("Clojure"); list.add("Groovy"); list.add("Scala"); List<String> result = new ArrayList<>(); for (String s …

Read more

Java – How to list all files in a directory?

Two Java examples to show you how to list files in a directory : For Java 8, Files.walk Before Java 8, create a recursive loop to list all files. 1. Files.walk 1.1 List all files. try (Stream<Path> walk = Files.walk(Paths.get("C:\\projects"))) { List<String> result = walk.filter(Files::isRegularFile) .map(x -> x.toString()).collect(Collectors.toList()); result.forEach(System.out::println); } catch (IOException e) { e.printStackTrace(); …

Read more

Apache Solr Hello World Example

Apache Solr is an Open-source REST-API based Enterprise Real-time Search and Analytics Engine Server from Apache Software Foundation. It’s core Search Functionality is built using Apache Lucene Framework and added with some extra and useful features. It is written in Java Language. SOLR stands for Searching On Lucene w/Replication. It’s main functionalities are indexing and …

Read more

ElasticSearch Hello World Example

ElasticSearch is an Open-source Enterprise REST based Real-time Search and Analytics Engine. It’s core Search Functionality is built using Apache Lucene, but supports many other features. It is written in Java Language. It supports Store, Index, Search and Analyze Data in Real-time. Like MongoDB, ElasticSearch is also a Document-based NoSQL Data Store. Note ElasticSearch website: …

Read more

Linux Search and Replace example

I was recently in a situation of having to change some text that appeared in a bunch of config files that were inside nested sub-directories. Not having time to dust off 10-year old perl skills, I was looking for some shell commands that would work. Surprisingly, there are many examples on the web that do …

Read more