zoukankan      html  css  js  c++  java
  • 字符串习题

    public class Test
    {
    	public static void main(String args[])
    	{
    		String s1 = "This is a dog";
    		String s2 = s1;
    		String s3 = "this is a dog";
    		String s4 = "This is a dog";
    		System.out.println("s1.equals(s2):" + s1.equals(s2));
    		System.out.println("s1.compareTo(s2):" + s1.compareTo(s2));
    		System.out.println("s1.equals(s4):" + s1.equals(s4));
    		System.out.println("s1.compareTo(s4):" + s1.compareTo(s4));
    		System.out.println("s1.equals(s3):" + s1.equals(s3));
    		System.out.println("s1.compareTo(s3):" + s1.compareTo(s3));	
    		/*
    			---------- 运行 ----------
    			s1.equals(s2):true
    			s1.compareTo(s2):0
    			s1.equals(s4):true
    			s1.compareTo(s4):0
    			s1.equals(s3):false
    			s1.compareTo(s3):-32
    			输出完成 (耗时 0 秒) - 正常终止
    		*/
    	}
    }

    public class Test
    {
    	public static void main(String args[])
    	{
    		String s1 = "This ";
    		String s2 = "is ";
    		String s3 = "a ";
    		String s4 = "String";
    		String sConcat = s1.concat(s2).concat(s3).concat(s4);
    		System.out.println(sConcat);
    		/*
    				---------- 运行 ----------
    			This is a String
    
    			输出完成 (耗时 0 秒) - 正常终止		
    		*/
    	}
    }


    	public static void main(String args[])
    	{
    		String s1 = "This ";
    		String s2 = "is ";
    		String s3 = "a ";
    		String s4 = "String";
    		String sConcat = s1.concat(s2).concat(s3).concat(s4);
    		String sCopy = String.copyValueOf(s1.toCharArray());
    		System.out.println("concat:" + sConcat + "
    copyValueOf:" + sCopy);
    		/*
    			---------- 运行 ----------
    			concat:This is a String
    			copyValueOf:This 
    
    			输出完成 (耗时 0 秒) - 正常终止
    		*/
    	}


  • 相关阅读:
    Oracle 10g 改机器名后监听不能启动 解决方案 TNS12541 TNS12545
    14.3.1 IMPDP 命令行选项
    14.3.2 调用IMPDP —— 导入表空间
    三十岁之前不必在乎的事
    正则表达式
    GridLayout and GridData
    非UI线程更新界面
    整理用Java实现数字转化成字符串左边自动补零方法
    stackLayout
    读写properties文件
  • 原文地址:https://www.cnblogs.com/dengshiwei/p/4258553.html
Copyright © 2011-2022 走看看