java中删除数组中的指定元素⽅法,数组和字符串互相转化⽅
法
⾸先先获得指定元素的位置:
int e=0;
int f=0;
String names[]={"美元","港币","欧元"};
for(int i=0;i<names.length;i++){
if(names[i].equals("港币")){
e=i;
}
}
System.out.println(e);//结果为1
然后删除数组中的指定元素:
public
class
RemoveObjectFromArray{
public
static
java中split的用法void
main(String args[]) {
int
[] test =
new
int
[] {
101
,
102
,
103
,
104
,
105
};
System.out.println(
"Original Array : size : "
test.length );
System.out.println(
"Contents : "
test = ve(test,
2
);
/
/removing element at index 2
//Size of array must be 1 less than original array after deleting an element System.out.println(
"Size of array after removing an element : "
test.length);
System.out.println(
"Content of Array after removing an object : "
}
}
Output:
Original Array : size :
5
Contents : [
101
,
102
,
103
,
104
,
105
]
Size of array after removing an element :
4
Content of Array after removing an object : [
101
,
102
,
104
,
105
java数组和字符串相互转换
,
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论