Java 语法 索引 ----- 字符串(String)

组合吃烤串的各种方法

String a = "Hello";
String b = new String(" World");

//在循环里面的话要小心用
String c = a+b; // Hello World
          a += b; // Hello World

String x = "Hello " + "World";

比较字符串

boolean x = a.equals(b); // compares string
boolean y = (a == b); // compares address

StringBuffer

//虽是sb但是确实很聪明
StringBuffer sb = new StringBuffer("Hello");

sb.append(" World"); // add to end of string 添加
sb.delete(0, 5); // remove 5 first characters 删除
sb.insert(0, "Hello"); // insert string at beginning 插入

String s = sb.toString();

Java 语法 索引 ----- 字符串(String),布布扣,bubuko.com

时间: 2024-10-13 07:54:12

Java 语法 索引 ----- 字符串(String)的相关文章

Java 语法 索引 ----- 主函数 (Main)

public class MyApp { public static void main(String[] args) { System.out.print("Hello World"); } } Java 语法 索引 ----- 主函数 (Main),布布扣,bubuko.com

Java 语法 索引 ----- 数组(Arrays)

数组声明,分配, 赋值 int y[] = new int[3]; y[0] = 1; y[1] = 2; y[2] = 3; int[] x = new int[] {1,2,3}; int[] x = {1,2,3}; 二维数组 String[][] x = {{"00","01"},{"10","11"}}; String[][] y = new String[2][2]; y[0][0] = "00"

Java 语法 索引 ----- 接口

interface MyInterface { void exposed(); } class MyClass implements MyInterface { public void exposed() {} public void hidden() {} } public static void main(String[] args) { MyInterface i = new MyClass(); } 参考文献: Java Quick Syntax Reference by Mikael

Java 语法 索引 ----- 继承(Inheritance) 和重写(Overriding)

// Superclass (parent class) class Fruit{ public String flavor; } // Subclass (child class) class Apple extends Fruit { public String variety; } //downcasting Apple a = new Apple(); Fruit f = a; Apple c = (f instanceof Apple) ? (Apple)f : null; 重写 cl

java学习-关于字符串String

有必要总结记录一下java的学习,否则,永远只是记忆碎片化和always google(费时) 刚好,小伙伴给了一份自己做的review,在学习的过程中,update一下自己的见解和学习内容: 关于String: 1 package string_keywords; 2 /** 3 * 参考url: http://developer.51cto.com/art/201106/266454.htm 4 * 5 * 常量池(constant pool)指的是在编译期被确定,并被保存在已编译的.cla

Java 语法 索引 ----- 变量-----数据类型

数据类型 类型 bits/byte 范围 默认值 byte 8/1 -128 +127 0 short 16/2 -32,768+32,767 0 int 32/4 -2,147,483,648 = -231+2,147,483,647 = 231-1 0 long 64/8 -9,223,372,036,854,775,808 = -263+9,223,372,036,854,775,807 = 263-1 0L float 32/4 1.40129846432481707e-45  = 2-

Java 语法 索引 ----- 条件语句(If Else,Switch)

if (x < 1) System.out.print(x + " < 1"); else if (x > 1) System.out.print(x + " > 1"); else System.out.print(x + " == 1"); Switch switch (y) { case 0: System.out.print(y + " is 0"); break; case 1: System

Java 语法 索引 ----- 运算符

算术运算符 float x = 3+2; // 5 // addition 加 x = 3-2; // 1 // subtraction 减 x = 3*2; // 6 // multiplication 乘 x = 3/2; // 1 // division 除 x = 3%2; // 1 // modulus (division remainder) 余数 Combined assignment operators int x = 0; x += 5; // x = x+5; x -= 5;

Java 语法 索引 ----- 循环(loop)

While 和  Do-While //while int i = 0; while (i < 10) { System.out.print(i++); } //do - while int i = 0; do { System.out.print(i++); } while ( i < 10 ); For 和 Foreach for (int i = 0; i < 10; i++){ System.out.print(i); } for (int k = 0, l = 10; k &l