Quên về mảng. Họ không phải là một khái niệm cho người mới bắt đầu. Theo thời gian, bạn nên đầu tư tốt hơn vào việc tìm hiểu API Bộ sưu tập.
/* Populate your collection. */
Set<String> colors = new LinkedHashSet<>();
colors.add("Red");
colors.add("Orange");
colors.add("Yellow");
...
/* Later, create a copy and modify it. */
Set<String> noRed = new TreeSet<>(colors);
noRed.remove("Red");
/* Alternatively, remove the first element that was inserted. */
List<String> shorter = new ArrayList<>(colors);
shorter.remove(0);
Đối với liên tác với các API di sản mảng dựa trên, có một phương pháp tiện dụng trong Collections
:
List<String> colors = new ArrayList<>();
String[] tmp = colorList.split(", ");
Collections.addAll(colors, tmp);
Cảm ơn người đàn ông! Tôi thực sự bắt đầu nó! – Barakados