From 644ecbd0ebbe12d1a70df6c98d3e9030a4448060 Mon Sep 17 00:00:00 2001 From: Mansi Date: Sat, 9 Sep 2017 03:29:23 +0530 Subject: [PATCH] BAEL-1090 Difference between Compressed String and Compact String in Java 9 (#2574) * Example Code For Evaluation Article This is an example code for the evaluation article on "Different Types of Bean Injection in Spring" * Added unit tests * Minor changes to application context * Removed code committed for evaluation article * BAEL-944 Demonstrating the problems with new Url pattern matching in Spring 5 * BAEL-944 Demonstrating the problems with new Url pattern matching in Spring 5 * BAEL-944 Exploring the Spring MVC URL Matching Improvements * BAEL-944 Exploring the Spring MVC URL Matching Improvements * BAEL-944 Exploring the Spring MVC URL Matching Improvements * BAEL-944 Code Formatting and solving build issue * BAEL-944 Resolving build issue due to change in Spring version * BAEL-944 Resolving build issue * BAEL-944 Formatting code * BAEL-944 Moving tests to correct package * BAEL-944 Moving tests to correct package * BAEL-944 Replacing @RequestMapping by @GetMapping * BAEL-944 Remove unnecessary attribute name, "value" in annotations * BAEL-79 Intro to Activiti with Spring * BAEL-79 Intro to Activiti with Spring * BAEL-79 Adding activiti module to the parent modules * BAEL-79 Using latest version * BAEL-79 Update Spring boot version that works with Activiti * BAEL-79 Replace RequestMapping with GetMapping * BAEL-79 Use Java 8 Syntax * BAEL-79 Formatting * BAEL-79 changed module name * BAEL-378 A Guide to Activiti with Java * BAEL-79 Fixed unit tests * BAEL-79 Simplified the process * BAEL-79 Fix test cases * BAEL-1045 Lambda Behave * BAEL-1045 Lambda Behave * BAEL-1045 Lambda Behave * BAEL-1090 Difference between compact and compressed strings in Java 9 --- .../compactstring/CompactStringDemo.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 core-java-9/src/main/java/com/baeldung/java9/compactstring/CompactStringDemo.java diff --git a/core-java-9/src/main/java/com/baeldung/java9/compactstring/CompactStringDemo.java b/core-java-9/src/main/java/com/baeldung/java9/compactstring/CompactStringDemo.java new file mode 100644 index 0000000000..6aa4ac3247 --- /dev/null +++ b/core-java-9/src/main/java/com/baeldung/java9/compactstring/CompactStringDemo.java @@ -0,0 +1,24 @@ +package com.baeldung.java9.compactstring; + +import java.util.List; +import static java.util.stream.Collectors.toList; +import java.util.stream.IntStream; + +public class CompactStringDemo { + + public static void main(String[] args) { + long startTime = System.currentTimeMillis(); + List strings = IntStream.rangeClosed(1, 10_000_000) + .mapToObj(Integer::toString).collect(toList()); + long totalTime = System.currentTimeMillis() - startTime; + System.out.println("Generated " + strings.size() + " strings in " + + totalTime + " ms."); + + startTime = System.currentTimeMillis(); + String appended = (String) strings.stream().limit(100_000) + .reduce("", (left, right) -> left.toString() + right.toString()); + totalTime = System.currentTimeMillis() - totalTime; + System.out.println("Created string of length " + appended.length() + + " in " + totalTime + " ms."); + } +}