• java语法记录


    字符操作

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Comparator;
    
    public class hello3 {
        public static void main(String[] args) {
            String str="To be or not to be is a question";
            String ss[]=str.split(" ");
            Arrays.sort(ss,(String o1,String o2)->o1.length()-o2.length());
            Arrays.sort(ss, Comparator.comparingInt(String::length));
            System.out.println(Arrays.toString(ss));
            String s=String.join("
    ",ss);
            System.out.println(s);
            ArrayList names=new ArrayList();
            names.add("1"); names.add("2"); names.add("3");
            System.out.println(String.join("-", names));
    
    
        }
    
    }
    
    

    二维各种数组比较

    import java.util.Arrays;
    
    public class hello3 {
        public static void main(String[] args) {
            String s1="abc";
            String s2="abc";
            String s3=new String("ab");
            System.out.println(s3.compareTo(s1));
    
            Object[][] a={{20,"male"},{21,"female"},{20,"female"},{19,"male"},{20,"male"}};
            Arrays.sort(a,(Object[] o1,Object o2[])->(int)o1[0]==(int)o2[0]?
                    ((String)o1[1]).compareTo((String)o2[1]):(int)o1[0]-(int)o2[0]);
            System.out.println(Arrays.deepToString(a));
        }
    }
    
    

    StringBuffer

    
    public class hello3 {
    
        public static void main(String[] args) {
            StringBuffer s1=new StringBuffer("");
            String s2=s1.toString();
    
            int n=8,m=3,k=0;
            for(int i=0;i<n;i++)s1.append((char)('A'+i));
            System.out.println(s1);
            while(s1.length()>1){
                k=(k+m-1)%s1.length();
                s1.deleteCharAt(k);
            }
            System.out.println(s1);
            System.out.println(s1.charAt(0)-'A'+1);
    
    
        }
    
    }
    
    

    //string valueOf
    public class Test {
    public static void main(String args[]) {
    double d = 1100.00;
    boolean b = true;
    long l = 1234567890;
    char[] arr = {'r', 'u', 'n', 'o', 'o', 'b' };

        System.out.println("返回值 : " + String.valueOf(d) );
        System.out.println("返回值 : " + String.valueOf(b) );
        System.out.println("返回值 : " + String.valueOf(l) );
        System.out.println("返回值 : " + String.valueOf(arr) );
    }
    

    }

    //
    import java.util.HashMap;
    public class J84 {
        public static void main(String[] args) {
            HashMap hp=new HashMap();
            String s="Jinan University";
            char ch;int i;
            for(i=0;i<s.length();i++){
                ch=s.charAt(i);
                if(('a'<=ch)&&(ch<='z'))
                    hp.put((char)(ch-32), (int)hp.getOrDefault((char)(ch-32), 0)+1);;
                if(('A'<=ch)&&(ch<='Z'))
                    hp.put(ch, (int)hp.getOrDefault(ch, 0)+1);
            }
            System.out.println(hp);
        }
    }
    
  • 相关阅读:
    08-图9 关键活动 (30 分)
    08-图8 How Long Does It Take (25 分)
    08-图7 公路村村通 (30 分)
    07-图6 旅游规划 (25 分)
    07-图5 Saving James Bond
    使用RichTextBox控件保存文件
    在RichTextBox控件中显示RTF格式文件
    在RichTextBox控件中插入图片
    在RichTextBox控件中添加超链接文本
    实现带查询功能的ComboBox控件
  • 原文地址:https://www.cnblogs.com/reshuffle/p/14076842.html
Copyright © 2020-2023  润新知