Five Java Delete array elements and repeating array instance code
This article from the network collection of Java Delete array elements oh, all kinds of delete array elements have their own method, here not only can delete the array elements, but also can delete duplicate array element instances.
Package Com.lzy;
Import Java.util.hashset;
Import Java.util.set;
public class Test {
/**
* @param args
*/
public static void Main (string[] args) {
Todo auto-generated method stub
string[] str = {"A", "C", "B", "A", "B", "D"};
Set<string> set=new hashset<string> ();
for (int i=0;i<str.length;i++) {
Set.add (Str[i]);
}
String[] A = (string[]) Set.toarray (new String[set.size ()));
for (int i=0;i<a.length;i++) {
System.out.println (A[i]);
}
}
}
Delete Array Method two
Package Com.akfucc.zhidao;
Import java.util.arraylist;
Import java.util.collections;
Import Java.util.iterator;
Import java.util.list;
public class p124876743 {
public static void Main (string[] args) {
Int[] Nums = {1, 2, 3, 3, 3, 3, 4};
list<integer> numlist = new arraylist<integer> ();
for (int i:nums)
Numlist.add (i);
System.out.println (numlist);
Do delete
Iterator<integer> it = Numlist.iterator ();
int temp =-1;
if (It.hasnext ())
temp = It.next ();
while (It.hasnext ()) {
int i = It.next ();
if (i = = temp) {
It.remove ();
} else {
temp = i;
}
}
System.out.println (numlist);
}
}
Java Delete repeating array element three
String[] a={1,2,3,4,5,6,7,8,9};
String[] b={1,3,6};
for (int i;i<b.length;i++) {
A.remove (B[i])//In fact, there is no remove method, I will not transform
}
return A;
Method Four
String[] Filter () {
ArrayList a=new ArrayList ();
for (int i=0;i<a.length;i++) {
Boolean find=false;
for (int j=0;j<b.length;j++) {
if (A[i].equals (B[j])) {
Find=true;
Break
}
}
if (False==find)
A.add (A[i]);
}
Return A.toarray (New string[]{})
}
Method Five
Public class Test {
public static void Main (string[] args) {
string[] A = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
int[] B = {0, 3, 6};//may change
&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&N Bsp How to remove elements from a[1 and 3 and 6] into a={1,3,5,6,8,9 ...}
string[] a0 = new String[a.length-b.length];
int currentindex = 0;
for (int i = 0; i < b.length; i++) {
for (int j = (i = = 0? 0:b[i-1] + 1); J < B[i]; J +) {
a0[currentindex++] = A[j];
}
P (A0);
}
for (int i = b[b.length-1] + 1; i < a.length; i++) {
a0[currentindex++] = A[i];
}
P (A0);
}
private static void P (string[] ss) {
for (string s: SS) {
system.out.print (s + "t");
}
System.out.println ();
}
}