java 创建一个字典,获取列表list的值,java字符串的截取,java输入字符串用标点符号进行分割,java输出字符串存储地址

java

1.java 创建一个字典
https://cloud.tencent.com/developer/ask/30271

Map maindic = new HashMap();
//键不能对应多个值,但是一个值被多个键对应,只能通过键查到值
maindic.put("馒头", (double) 1);
//获取值的话,需要用
maindic.get(···)

2.获取列表list的值,和数组不同,不能直接访问

List midl = new ArrayList<>(Arrays.asList(prices));
        Collections.sort(midl);
        order =new int[]{dic.get(midl.get(0)),dic.get(midl.get(1)),dic.get(midl.get(2))};//用到get

3.字符串截取
https://blog.csdn.net/vv___/article/details/78492925
4.字符串用标点符号进行分割
两种方法:
法一:用spilt进行分割

Scanner readIn = new Scanner(System.in);
System.out.println("输入组句,用中文逗号隔开");
            String sentence = readIn.nextLine();
            String[] parts = sentence.trim().split(",");//用spilt分割
            nS.subject = parts[0];
            nS.verb = parts[1];
            nS.object = parts[2];

法二:用StringTokenizer类进行分割

StringTokenizer parts = new StringTokenizer(sentence,",");
            nS.subject = parts.nextToken();
            nS.verb = parts.nextToken();
            nS.object = parts.nextToken();

5.java 输出字符串的地址str.hashCode()

String str2;
str2 ="法语";
System.out.println(str2.hashCode());

你可能感兴趣的:(JAVA)