[Java] Collection and StringBuilder operation method comparison

Method Collection interface StringBuilder class
add to add() append()
Insert add() insert()
Delete remove(), removeAll(), removeIf() delete(), deleteCharAt()
Rewrite set(), replace() setCharAt()
length size() length()

public static void main(String[] args) {

		StringBuilder sb = new StringBuilder(10);
		System.out.println(sb.length()); // #=> 0
		sb.append("123456", 1, 3);
		sb.append("a");
		sb.setCharAt(0, 'c');
		sb.insert(1, "d");
		System.out.println(sb);  // #=> cd3a
		sb.replace(0, 2, "ab");
		sb.delete(0, 1);
		sb.deleteCharAt(0);
		
		List<String> list = new ArrayList<>();
		list.add("a");
		list.add("a");
		list.add("a");
		list.set(0, "b");
		list.add(1, "b");
		System.out.println(list);  // #=> [b, b, a, a]
		list.remove(0);
		list.remove("b");
		list.removeIf(s -> s.length() > 2);
		System.out.println(list);  // #=> [a, a]
		list.removeAll(Arrays.asList("a", "b"));
		list.size();
	}

reference

Recommended Posts

[Java] Collection and StringBuilder operation method comparison
[Java] String comparison and && and ||
Java test code method collection
[Java] About String and StringBuilder
Java methods and method overloads
[Java] Comparison method of character strings and comparison method using regular expressions
Java comparison using the compareTo () method
StringBuffer and StringBuilder Class in Java
[Java] Difference between StringBuffer and StringBuilder
Java method
java (method)
☾ Java / Collection
[Java] method
[Java] method
Java Silver exam procedure and learning method
Element operation method in appium TIPS (Java)
[Java] TreeMap successor method and entrySet complexity
[Java] Contents of Collection interface and List interface
Comparison of thread implementation methods in Java and lambda expression description method
[Member and collection]
Chrome59 Comparison of normal and headless mode operation
Java8 method reference
Java Reintroduction-Java Collection
[Java] forEach method
Kantai Collection Java # 1 Classes and Objects [For Beginners]
[Java] Map comparison
variable and method
Java framework comparison
Java and JavaScript
XXE and Java
Java and Swift comparison (3) Class implementation / Class inheritance / Class design
java8 method reference
[Java beginner] println method without collection type specification
[Java] Random method
[Java] split method
[Java] Collection framework
The comparison of enums is ==, and equals is good [Java]
[Java] String join execution speed comparison (+ operator vs StringBuilder)
Equivalence comparison of Java wrapper classes and primitive types
[Java] Handling of character strings (String class and StringBuilder class)
Expired collection of java
Java collection interview questions
JAVA DB connection method
Getters and setters (Java)
[Java] Thread and Runnable
Java learning 2 (learning calculation method)
Java true and false
Java version notation comparison
Java learning memo (method)
About Java method binding
[Java ~ Method ~] Study memo (5)
About method splitting (Java)
Studying Java 8 (see method)
Comparison operators and conditionals
Java programming (class method)
[Java] Arguments and parameters
Java8 Stream reduction operation
timedatectl and Java TimeZone
[Java] Branch and repeat
[Development] Java framework comparison
Java --StringBuilder vs StringBuffer