@@ -163,43 +163,4 @@ public static UiFormSchemaGenerator get() {
163163
164164 private UiFormSchemaGenerator () {
165165 }
166-
167- public static void main (String [] argv ) {
168-
169- Map <String , Integer > unsortMap = new HashMap <>();
170- unsortMap .put ("z" , 10 );
171- unsortMap .put ("b" , 5 );
172- unsortMap .put ("a" , 6 );
173- unsortMap .put ("c" , 20 );
174- unsortMap .put ("d" , 1 );
175- unsortMap .put ("e" , 7 );
176- unsortMap .put ("y" , 8 );
177- unsortMap .put ("n" , 99 );
178- unsortMap .put ("g" , 50 );
179- unsortMap .put ("m" , 2 );
180- unsortMap .put ("f" , 9 );
181-
182- System .out .println ("Original..." );
183- System .out .println (unsortMap );
184-
185- // sort by keys, a,b,c..., and return a new LinkedHashMap
186- // toMap() will returns HashMap by default, we need LinkedHashMap to
187- // keep the order.
188- Map <String , Integer > result = unsortMap .entrySet ().stream ().sorted (Map .Entry .comparingByKey ())
189- .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue , (oldValue , newValue ) -> oldValue ,
190- LinkedHashMap ::new ));
191-
192- // Not Recommend, but it works.
193- // Alternative way to sort a Map by keys, and put it into the "result"
194- // map
195- Map <String , Integer > result2 = new LinkedHashMap <>();
196- unsortMap .entrySet ().stream ().sorted (Map .Entry .comparingByKey ())
197- .forEachOrdered (x -> result2 .put (x .getKey (), x .getValue ()));
198-
199- System .out .println ("Sorted..." );
200- System .out .println (result );
201- System .out .println (result2 );
202-
203- }
204-
205166}
0 commit comments