2020-12-10 03:05:29 +00:00
/ *
* The MIT License ( MIT )
*
* Copyright © 2020 xrv < xrg @live.com >
*
* Permission is hereby granted , free of charge , to any person obtaining a copy
* of this software and associated documentation files ( the "Software" ) , to deal
* in the Software without restriction , including without limitation the rights
* to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
* copies of the Software , and to permit persons to whom the Software is
* furnished to do so , subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED "AS IS" , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
* LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE .
* /
2020-12-09 09:55:24 +00:00
package io.github.ehlxr.test ;
2016-12-19 08:47:38 +00:00
2021-08-12 15:15:14 +00:00
import java.io.IOException ;
2021-02-20 10:02:28 +00:00
import java.util.Arrays ;
2021-02-20 02:40:35 +00:00
import java.util.LinkedHashMap ;
2021-02-20 10:02:28 +00:00
import java.util.List ;
import java.util.StringJoiner ;
import java.util.stream.Collectors ;
2021-02-20 02:40:35 +00:00
2016-12-19 08:47:38 +00:00
/ * *
2020-12-09 09:27:50 +00:00
* Created by ehlxr on 2016 / 12 / 15.
2016-12-19 08:47:38 +00:00
* /
public class Test {
2021-08-12 15:15:14 +00:00
public static void main ( String [ ] args ) throws IOException {
2021-02-20 10:02:28 +00:00
// String s0 = "kvill";
// String s1 = "kvill";
// String s2 = "kvill";
// System.out.println(s0 == s1);
// System.out.println("**********");
// s1.intern();
// s2 = s2.intern(); //把常量池中"kvill"的引用赋给s2
// System.out.println(s0 == s1);
// System.out.println(s0 == s1.intern());
// System.out.println(s0 == s2);
2021-02-20 02:40:35 +00:00
// LinkedHashMap
System . out . println ( "*****LinkedHashMap*****" ) ;
LinkedHashMap < Object , Object > map = new LinkedHashMap < > ( ) ;
map . put ( "a" , "111" ) ;
map . put ( "b" , "222" ) ;
map . put ( "c" , "333" ) ;
map . put ( "d" , "444" ) ;
map . put ( "a" , "555" ) ;
System . out . println ( map ) ;
2021-02-20 10:02:28 +00:00
// The String "[George:Sally:Fred]" may be constructed as follows:
StringJoiner sj = new StringJoiner ( ":" , "[" , "]" ) ;
sj . add ( "George" ) . add ( "Sally" ) . add ( "Fred" ) ;
System . out . println ( sj ) ;
// A StringJoiner may be employed to create formatted output from a java.util.stream.Stream using java.util.stream.Collectors.joining(CharSequence). For example:
List < Integer > numbers = Arrays . asList ( 1 , 2 , 3 , 4 ) ;
String commaSeparatedNumbers = numbers . stream ( )
. map ( Object : : toString )
. collect ( Collectors . joining ( ", " ) ) ;
System . out . println ( commaSeparatedNumbers ) ;
System . out . println ( "------------" + ( - 1 > > > Integer . numberOfLeadingZeros ( 3 ) ) ) ;
String s = new String ( "1" ) ;
String t = new String ( "1" ) ;
String s1 = s . intern ( ) ;
String s2 = "1" ;
System . out . println ( s = = s1 ) ;
System . out . println ( s1 = = s2 ) ;
System . out . println ( s = = t ) ; // false
System . out . println ( s . intern ( ) = = t . intern ( ) ) ; // true
2021-08-12 15:15:14 +00:00
System . in . read ( ) ;
2016-12-19 08:47:38 +00:00
}
}