我想从jlist
中的数组输出中删除一个项目String[] cdList = {"Adele", "Drake", "Prince", "Rihanna", "Sia"} ;
输出
String[] cdList = {"Adele", "Drake", "Prince", "Sia"} ;
答案 0 :(得分:1)
这可以帮到你:
List<String> list = new ArrayList<String>(Arrays.asList(cdList));
list.remove(cdList[i]);
cdList = list.toArray(new String[0]);
我已经这样写了,享受!
String[] cdList = {"Adele", "Drake", "Prince", "Rihanna", "Sia"} ;
for(int i = 0; i< cdList.length;i++){
System.out.println(i+1 + " . " + cdList[i]);
}
System.out.println("Enter the number of the name you want to remove:");
Scanner scan = new Scanner(System.in);
int num = scan.nextInt();
List<String> list = new ArrayList<String>(Arrays.asList(cdList));
list.remove(cdList[num-1]);
cdList = list.toArray(new String[0]);
for(int i = 0; i< cdList.length;i++){
System.out.println(i+1 + " . " + cdList[i]);
}
喝彩!