Explore several approaches to asserting regex matches in JUnit, empowering us to test our string patterns effectively.
Kai Yuan has been a software developer for over 15 years. He builds enterprise Java applications in work. He has 20 years experience of Linux and is a big fan of the Vim editor. He is happy to help people at stackoverflow.com. He lives currently in Hamburg.
Here's what I've written (so far):
Baeldung on Java
- Java (40)
- Java Collections (32)
- Java String (21)
- Programming (6)
- Testing (3)
- Maven (3)
- Spring Boot (2)
- Persistence (2)
- Java Concurrency (2)
- XML (1)
- REST (1)
- Java Numbers (1)
- Jackson (1)
- JSON (1)
- IDE (1)
Explore various approaches to splitting an integer number into its constituent digits using Java.
Explore how to create a list of objects of a different type based on a given list.
Discuss interesting usages of –> in Java.
Explore obtaining the indexes of pattern matches within the original input when using a Java regex.
Explore how to extract content between square brackets in a text.
Explore how to obtain the key and value lists from a HashMap in Java.
Learn the steps to retrieve the first n elements from a List and convert them into an array in Java.
Learn different approaches to convert a Java String ArrayList to a String array through examples.
Learn a few ways to remove duplicate values from a Java HashMap.
Learn how to use Java’s Iterator and ListIterator and explore the key differences between them.
Learn the remove() then put() approach to replacing a key in a Java HashMap.
Explore two effective approaches for converting a Long to a BigDecimal in Java.
Explore different approaches and techniques for breaking an input string into a string array or list containing digit and non-digit string elements in the original order
Explore a few efficient and straightforward ways to check if a file is empty in Java.
Learn three ways of converting a list of strings to a list of integers.
Explore different approaches to check if a string is all uppercase or lowercase in Java.
Explore different approaches to effectively sorting date strings in Java.
Explore a few techniques for obtaining unique values from an ArrayList in Java.
Learn different ways to convert a Map to Map.
Learn how to set three main configuration options to disable wildcard imports in Java files in IntelliJ.
Explore various approaches to initialize a Java List with default values.
Lern how to make System.out.println() print data to a file by replacing the default System.out
Learn how to read values containing spaces from a Scanner through examples.
Explore two approaches to converting an OutputStream to an InputStream: using a byte array and a pipe.
Learn how to store the input from a Scanner into an array with three different scenarios and examples.
Learn common pitfalls when comparing the contents of two arrays and explore the correct way to compare two byte arrays.
Learn how to remove punctuation from a string using the standard String.replaceAll() method.
Explore three different approaches to printing a string with quotes (“) around it.
Learn the differences between char and String in Java.
Learn three approaches to finding the most frequent characters in a string, with examples.
Learn two variations on the problem of extracting text that follows after a regex match and how to do it using Java.
Learn the differences between Integer.parseInt(Scanner.nextLine()) and Scanner.nextInt() through examples.
Learn how to generate the same UUID objects from a string.
Explore various ways of converting boolean values to strings.
Learn a few ways of converting an integer to an English letter.
Learn whether Java’s Stream.collect() can return null.
Explore two approaches to handling duplicated keys when producing a Map result using Stream API.
Learn three ways to combine two given lists into a map through examples
Learn two ways to check if a given object is an array.
Learn about Stream.of() and IntStream.range() and learn about certain operations that may turn a Stream from “lazy” to “eager”.
Learn three approaches to verifying multiple properties in one assert call using JUnit5 and AsssertJ.
Explore calculating the absolute difference between two integers.
Learn a few different ways to check if a given Integer instance’s value is null or zero.
Learn how to compare a String to an enum constant through examples.
Learn a few ways to multiply BigDecimal by an Integer.
Explore how to store triples in a list with examples.
Learn three approaches to perform case-insensitive searching in ArrayList.
Learn how to use the Class.forName() method to obtain the Class object.
Learn two ways to convert a string array to an integer array through examples
Learn two approaches to extracting a JAR file to a specified directory
Learn three ways to convert a list of integers to a list of strings in Java.
Learn three approaches to get a List object that contains all instances of an enum
Learn how to get a subarray of a given array in Java
Learn the difference between instantiating a URI object using the constructor and the URI.create() method.
Learn two common pitfalls when we work with integer literals in Java.
Explore how to convert a String into a String array (String)
Learn how to convert a String to a char in Java.
Learn how to convert a given string’s first character to upper case.
Explore how to collect elements in a Stream into a TreeSet.
Learn how to initialize a boolean or Boolean array in Java.
Learn how to extract the filename from an absolute path using core Java and Apache Commons.
Learn why the division of integers results in integers and how to get a float result.
Learn multiple ways to remove the last character from a StringBuilder sequence
Learn how to find all factors of an integer using Java.
Learn how to check if an integer is an Armstrong number and generate OEIS sequence A005188 up to a given limit
Learn how to build a null-safe method to toggle a given boolean variable in Java
We’ll discuss a few ways to solve a simple problem: how to check whether a given number is positive or negative in Java
Learn how to replace parameters in template-based strings from a set of values
Learn about the Arrays.asList() method and the Collections.singletonList() method
Explore common scenarios of removing whitespace from a String in Java
Explore how to find the JAR file and its full path from a given class
Explore a few different approaches to check if there are at least two trues in three given booleans
Explore how to check if a BigDecimal object’s value is zero and learn a common pitfall
Learn how to reverse an ArrayList through examples
Learn how to remove a file or directory from a Git repository but keep its local copy
Learn how to get the Git branch name we’re currently working on
Learn how to delete Git branches
Learn a couple of quick ways to move uncommitted changes to a new Git branch
Take a closer look at the Java List of Lists data structure and explore some everyday operations
Explore how to convert file size in bytes into a human-readable format in Java
Learn why we may encounter the Java compile-time error “bad operand types for binary operator” and how to resolve the problem
Learn how to find the asymmetric and symmetric differences between two Set objects through examples
Learn how to handle multiple-line user input in Java
Walk through all Java operators to understand their functionalities and how to use them
Learn two approaches to pretty-print an XML file in Java
Learn two approaches to read content from a text file and save it in a Java Map object along with three strategies to handle duplicate keys
Learn two approaches on how to make a Java HashMap support different types’ value data
Learn how to invoke public and private static methods using the Java Reflection API
Learn how to set the Java classpath on different operating systems and what to watch out for.
Learn how to remove all HTML tags and extract the text from an HTML document string
Learn various ways to count how many spaces are in a string through examples
Learn what Git squashing is, talk about when we need to squash commits, and take a closer look at how to squash commits
Learn how to execute tests during a Maven build using the Maven surefire plugin
Learn how to temporarily disable the Javadoc generation in Maven builds.
Learn if java.sql.Connection implementations are thread-safe
Learn two approaches to start two threads simultaneously: using CountDownLatch and CyclicBarrier
Learn how to concatenate two arrays in Java using the standard Java API and commonly used libraries
Compare the Java Stack class and the Deque interface and learn why we should use Deque over Stack for LIFO stacks
We’ll discuss what “unchecked cast” compiler warning means, why we’re warned, and how to solve the problem
Take a deeper look at the “unchecked conversion” compiler warning message
Learn why the “java.lang.ClassCastException: java.util.LinkedHashMap cannot be cast to X” exception occurs and how to solve the problem
Learn the difference between mvn:package and spring-boot:repackage
Learn ways to list a JAR file’s content from the command-line
Take a closer look at the JDBC URL formats of several widely used databases: Oracle, MySQL, Microsoft SQL Server, and PostgreSQL
Learn various ways to remove the extension from a filename
Learn how to extend Enums in Java.
Take a closer look at Java’s AbstractMethodError and understand what it is and when it may happen
Learn how to get names of classes inside a given JAR file and how to load classes from a JAR file at runtime.
Learn how to get the HTTP port programmatically in a Spring Boot application
Learn the differences between calling the Object.getClass() method and using the .class syntax
Learn about the difference between the two regular expressions through examples
See examples that illustrate the main causes of the “illegal start of expression” error and how to fix it
Baeldung on Linux
- Files (54)
- Scripting (41)
- File Editing (21)
- Administration (16)
- Processes (10)
- File Searching (10)
- Filesystems (6)
- File Viewing (5)
- Search (3)
- File Permissions (3)
- Web (2)
- Security (1)
- File Compression (1)
Learn how to extract specific lines from a file by line numbers using sed and awk.
Learn how to replace the first n pattern occurrences in a file using sed and awk.
Learn to use various techniques to operate on files listed in a file.
Learn the meaning of the special shell variable $!.
Learn how to extract text between two specific characters using grep, sed, and awk through examples.
Learn how to list files whose filenames don’t match a given pattern.
Explore different ways of checking whether a date argument is in the “yyyy-mm-dd” format.
Learn three ways to find lines exceeding a specific length in a file.
Explore how to get the kernel command-line parameters in the current running Linux system
Learn three ways to print a command’s output and the total number of lines in one shot.
Learn three approaches for awk to print records in the same line with examples.
Learn how to use the grep command to filter strace’s output.
Learn how to search multiple strings using only one grep process
Learn how to tell find to output only filenames without extensions.
Learn three approaches to using an external command to process shell variables
Learn how to sum up the size of listed files using the ls and find commands
Learn two methods to recursively find statistics on file types in a directory
Learn how to get an executable’s path when it’s in an alias
Learn how to output a blank line after each line in the file using Linux command-line tools.
Learn how to implement a customizable, reusable command line progress bar using shell script.
Learn how to set column rulers in the Vim editor and customize them.
Explore how to overwrite an output line using the echo and printf commands.
Learn how to list only the names of the files that match the given pattern.
Learn how to find the user’s name by a given UID
Learn how to find desired processes and preserve the header line of ps’s output.
Learn how to find processes’ information by a keyword.
Learn how to check the cron jobs’ logs for two common cron implementations and two different logging systems.
Learn how to use the find command to list non-empty files under a directory
Learn some tricks to reuse different parts from the last command in Bash
Start from a script example and discuss a case we should avoid using && when writing shell scripts
Learn how to use awk to remove duplicate lines from an input file
Learn how to identify the current user in Linux
Learn how to add a new column to a given TSV file in the Linux command line
Explore how to get the process name by a given PID
Learn how to use Bash’s += operator and parameter expansion to concatenate variables
Learn the difference between sourcing a script and executing a script in Linux through examples
Learn how to clear only a file’s content from the Linux command line and keep the empty file
Learn how to check if the current Java environment is Oracle JDK or OpenJDK
Learn how to parse CSV format data in Bash through examples
Learn how to search a pattern and apply some text substitution in the next line using sed and awk
Learn three approaches to search for a pattern in a file, starting after a given line number
Learn two approaches to extracting fields from input when the delimiter is multiple spaces
Learn how to list the files in a Zip archive without decompressing it
Learn why Regex \d isn’t supported by Linux commands such as grep and sed
Learn how to substitute shell variables with their values in a text file in the Linux command line
Learn three approaches using grep to search files and move the found files to a directory in one shot
Take a closer look at the /bin/true and /bin/false commands with some use cases
Learn how to do grep on a tar.gz archive to find which files contain an interesting pattern
Learn how to swap two files’ content using three mv commands
Learn how to perform various rounding methods in Bash
Learn how to set environment variables only for one single command
Learn how to only print the n-th line after the match using grep, sed, and awk
Learn how to return different values from sed and awk depending on the substitution result
Learn how to use the xargs command to handle multiple arguments
Learn how to use the find and tar commands to archive files of certain types
Learn approaches to run a command as the superuser without asking for a password
Learn how to copy directories recursively while excluding hidden files and directories
Take a closer look at wget’s timeout settings
Our Linux distro may contain a mixture of 32 and 64 bit libraries. We can find out the architecture the library was built for by using a couple of commands. We explore how to do this for static and shared libraries.
Learn how to use the ls command to list one file per line
Learn how to include additional scripts in the .bashrc file through examples
Take a closer look at how to use the sed command’s feature for inserting a new line when the new line contains spaces
Learn two ways to get the last word from each line of a file
Learn how to build simple shell scripts to log the CPU usage of a single process
Learn how to get a directory’s last modification time and what changes to a directory will affect the modification time
Learn how to column-wise combine two input files through examples
Learn how to split an input file with the header line using the split and awk commands
Learn several ways to open a URL in the default browser from the Linux command line
Learn how to delete files listed in another file using pure Bash, xargs, sed, and awk
Learn how to delete lines from a given line number until the end of the file using head, sed, and awk
Learn different approaches to read a specific line from a file
Learn how to extract the last component from a given path string
Learn two different ways to get the current login user in the shell script and a few common pitfalls
Learn various ways to extract substrings using the Linux command line
Learn how to recursively copy a directory to an existing directory with or without overwriting
Learn how to overcome the “Permission denied” error when redirecting output to a file.
Learn how to remove the last character from all lines in a file through examples
Learn how to remove a symbolic link using the rm and unlink commands
See why linebreaks in a shell variable can disappear in echo’s output and learn the right way to use shell variables in commands
Learn three different ways to delete files or directories found by the find command
Learn how to execute grep on a set of filtered files
Learn how to extract data lines between two patterns.
Learn how to create soft links to directories through examples
Learn two approaches to get all groups defined on the system
Learn three different ways to clone a directory structure without copying files under it through examples
Learn how to create the non-existing target directory automatically when we copy files
Learn how to search for files not owned by a particular user using the find command
Learn how to change a user’s default shell through examples
Take a closer look at how to do multiple variable assignment in Bash scripts
Learn how to send a GUI notification from a shell script using notify-send and zentity
Take a closer look at some common mistakes made using sed substitution with shell variables
Learn how to evaluate XPath expressions using xmllint, XMLStarlet, and xidel
Have a look at how to use the sed command to process a literal string or shell variable.
Learn how to remove the first line from using sed, awk, and tail
Learn about each type of Vim register through examples
Learn several approaches to remove the lines that appear in file B from another file A
Learn different ways to remove the last n lines from an input file and the performance of those approaches
Learn how to split a file at given line numbers using head, tail, sed, and awk
Learn how to delete multiple files in one shot from the Linux command line
Learn how to call shell script functions from outside the shell script file
Learn a few ways to count repeated lines in a text file
Learn how to implement a counter in a Bash script and some common pitfalls
Learn how to do in-place editing with the awk command through examples
Learn how to search and replace in text files recursively through examples
Learn how to determine virtualization technology using Linux commands
Learn how to send the output of a command to multiple commands using three different solutions through examples
Learn different ways to find the longest lines from an input file and benchmark their performance
Learn several ways to pretty-print an XML file using Linux commands
Learn a few ways to save multi-line output into a Bash array
Learn several ways to list all shared libraries used by a program
Learn how to call an external program using awk
Learn about three common approaches to start a process and let it run in the background as a job
Compare different ways to shuffle lines in text and discuss their pros and cons
Explore some common scenarios for removing blank lines from a file through practical examples
Learn several ways to merge multiple lines of input into a single line with customized delimiters
Learn how to process multiple input files using the awk command using simple examples
Learn how to get login related information using the last and lastb commands
Learn some useful commands to reboot and shut down a Linux system from the command line
Learn how to do the “uniq” operation on a column instead of the entire line
We’ll take a closer look at the date utility and learn its common usages
Learn about the typical usages of the head and tail command through examples.
Learn how to use the watch command to execute a command periodically and check the output of each execution
Learn the echo command and its options through examples
Learn the sort command through various examples
Learn about special file permission flags in Linux
Learn how to use the tr command through various examples
Learn about two types of file locks in Linux some related commands through examples
Learn about MIME types and how to get the MIME type of a file using Linux command-line utilities
Depending on the Linux distro and use case, there are a few available tools that can rename a batch of files. We explore some common use cases.
Learn different approaches to finding the process listening on a particular port in Linux
Learn how to use the Linux mount command to attach various filesystems and detach them with umount
Learn about some useful file manipulation commands in Linux.
Learn how to perform some common text searching in Linux using the grep command-line utility
Baeldung on Kotlin
- Kotlin Collections (11)
- Kotlin Classes and Objects (8)
- Kotlin Numbers (7)
- Kotlin Basics (7)
- Kotlin Strings (6)
- Kotlin (2)
- Security (1)
- Kotlin Functions (1)
Learn two approaches to reversing a positive integer and discuss the integer overflow case with examples.
Explore computing the quotient and remainder using the division and the modulus operators.
Learn two algorithms for finding the largest of three (and more) numbers and compare their performance.
Learn how to create an idiomatic solution to determine if a Kotlin Number is positive, negative, or zero.
Explore through examples two functions to reverse a list in Kotlin: reversed() and asReversed().
Explore two approaches of dividing two integers and obtaining a BigDecimal.
Explore various techniques to shuffle a list in Kotlin.
Explore different approaches to retrieving enum entry names.
Explore how to implement a flexible, extensible, and robust password validation in Kotlin.
Learn different techniques for prepending an element to a list in Kotlin.
Take a closer look at Kotlin’s get operator and explore different approaches to get a not-null value from a Map.
Learn a few ways to reverse a map through examples using Kotlin.
Learn how to convert between camel case and snake case strings through examples.
Learn three approaches to flattening a list of lists with examples.
Learn how to mark unused parameters in Kotlin’s regular functions and lambda expressions.
Learn how to use the with() scope function in Kotlin
Learn how to get the type name of a variable in Kotlin
Explore how to implement the “multi-catch” feature in Kotlin
Learn how to convert a string into an enum constant in Kotlin.
Learn two ways to turn Kotlin string templates into literal strings.
Learn how to create a “static” method in Kotlin’s enum class and how to call it from Java
Learn how to find an enum instance by a given value.
Learn about Kotlin data class’s equals() method and common pitfalls.
Learn about trailing comma support and its benefits.
Learn how to extend a class and implement interfaces simultaneously in Kotlin
Learn two approaches to convert a Boolean object to an Int through examples
Learn how to apply let-like operations on multiple variables
Learn how to pad numbers in Kotlin using two approaches: String.format() and padStart()/padEnd()
Learn how to add an element to Kotlin’s three common list types
Learn how to check the type of a given object in Kotlin and two kinds of cast approaches
Look into the compilation error “Smart cast to type is impossible” caused by Kotlin’s smart-casting a nullable type to the corresponding not-nullable type
Learn how to check nullable Boolean (Boolean?) values in Kotlin if statements
Learn how to check whether an Array contains a given element in Kotlin
Learn how to compare two List objects with or without checking the elements order
Learn three ways to format decimal numbers in Kotlin
Learn how to instantiate an abstract class or interface using object expressions in Kotlin
Explore two approaches to instantiate a Kotlin data class using an empty constructor
Learn the Kotlin way of declaring and assigning multiple variables in one line
Learn how to convert a List into an Array in Kotlin
Learn how to convert between Set and List in Kotlin