- 필수 기능
- 시작하기
- Glossary
- 표준 속성
- Guides
- Agent
- 통합
- 개방형텔레메트리
- 개발자
- API
- Datadog Mobile App
- CoScreen
- Cloudcraft
- 앱 내
- 서비스 관리
- 인프라스트럭처
- 애플리케이션 성능
- APM
- Continuous Profiler
- 스팬 시각화
- 데이터 스트림 모니터링
- 데이터 작업 모니터링
- 디지털 경험
- 소프트웨어 제공
- 보안
- AI Observability
- 로그 관리
- 관리
ID: java-best-practices/replace-vector-with-list
Language: Java
Severity: Warning
Category: Best Practices
Replace your Vector
class usage with the newer java.util.ArrayList
, unless you need expensive thread-safe operations.
Vector
uses unnecessary synchronization, which can slow down single-threaded applications whereas ArrayList
can perform better in such cases. In addition, it offers modern features which make the transition easy while retaining flexibility for thread safety when needed.
public class Foo {
void bar() {
Vector vector1 = new Vector(); // consider using java.util.List instead
Vector<Integer> vector2 = new Vector<>();
}
}
package com.dd.logs.rum.sessionreducer;
import static io.vavr.API.Vector;
import com.dd.logs.launcher.Features;
import com.dd.logs.launcher.ModuleLauncher;
import com.dd.logs.rule_engine.reducer.main.ReducerWorkloadBundle;
import com.dd.logs.usage.UsageComponent;
import com.dd.logs.usage.UsageTrackerClientBundle;
import com.dd.logs.workload.assigner.AssignerClientBundle;
import io.vavr.collection.Vector;
import java.util.List;
public class Main {
public static void main(String[] args) {
new ModuleLauncher(
List.of(
new AssignerClientBundle(),
new UsageTrackerClientBundle(UsageComponent.SESSIONIZATION),
new ReducerWorkloadBundle(new RumReducerWorkloadBundleParams())),
// disconnected from mongo
Features.builder().withKafka().build())
.launchOrExit();
Vector<String> x = returnSomeVavrVector();
x.stdout();
}
private static Vector<String> returnSomeVavrVector() {
return Vector();
}
}
public class Foo {
void bar() {
List list = new ArrayList();
List<Integer> list2 = new ArrayList<>();
}
}