Category: Java Basics

Traversal of HashMap 0

Traversal of HashMap

Traversal of HashMap HashMap<String, String> map=new HashMap<String, String>(); map.put("1", "Jack"); map.put("2", "Rose"); map.put("3", "Tom"); Method 1: First call the KeySet() method of the Map object to obtain the Set [collection] method of the Map...

System.out.println impact on performance 0

System.out.println impact on performance

Talk about System.out.println you don’t know In the process of developing or debugging bugs, some students often use the System.out.println statement to output to the console to check whether the data is normal. After...

Shuffle and deal cards in the Landlord mini-game 0

Shuffle and deal cards in the Landlord mini-game

code public class PokerShuffleCards { public static void main(String[] args) { ArrayList<String> color = new ArrayList<String>(); color.add("♠"); color.add("♥"); color.add("♦"); color.add ( "♣" ); // Prepare the numbers, sort the cards from small to large...

Set language level to 8 – Lambdas, type annotations etc. A grammar needs to set the jdk1.8 version 0

Set language level to 8 – Lambdas, type annotations etc. A grammar needs to set the jdk1.8 version

Solution: Method 1: Add the relevant configuration in pom.xml <!–pom.xml–> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>utf-8</encoding> </configuration> </plugin> </plugins> </build> Method 1: Change the Target bytecode version to a higher version,...

Round a double value to two decimal places 0

Round a double value to two decimal places

When dealing with numerical operations, sometimes you will encounter the need to retain several decimal places. The following is a simple method to retain two decimal places. /** * Data to two decimal places...

Lambda expression details 0

Lambda expression details

Introduction to [Lambda Lambda] expression is a new feature of JDK8, which can replace most anonymous inner classes and write more elegant Java code, especially in collection traversal and other collection operations, which can...

Java replace() method 0

Java replace() method

The replace() method returns the new string after replacement by replacing all occurrences of searchChar characters in the string with newChar characters. grammar public class Main { public static void main(String args[]) { String...