The
looks like this:
Import java.util.List;
Import java.util.ArrayList;
Import Java.util.Set;
Import Java.util.HashSet;
public class Lzwcode {public static void main (String [] args) {testa ();
System.out.println ("===========================");
Testb ();
System.out.println ("===========================");
TESTC ();
//Remove duplicate values in array public static void Testa () {String [] str = {"Java", "C + +", "Php", "C #", "Python", "C + +", "Java"};
for (String elementa:str) {System.out.print (Elementa + "");
} list<string> List = new arraylist<string> ();
for (int i=0; i<str.length; i++) {if (!list.contains (str[i))) {List.add (str[i]);
}/* Set<string> Set = new hashset<string> ();
for (int i=0; i<str.length; i++) {set.add (str[i]);
} string[] Newstr = Set.toarray (new string[1));
* * SYSTEM.OUT.PRINTLN (); string[] Newstr = List.toarray (new string[1)); Returns an array of the specified types containing all objects for (String elementb:newstr) {System.out.print (ELEMENTB +" ");
} System.out.println ();
//Delete One of the elements in the array public static void Testb () {String [] str = {"Java", "C + +", "Php", "C #", "Python"};
for (String elementa:str) {System.out.print (Elementa + "");
}//delete php list<string> List = new arraylist<string> ();
for (int i=0; i<str.length; i++) {list.add (str[i]); } list.remove (2);
List.remove ("Php") System.out.println (); string[] Newstr = List.toarray (new string[1));
Returns an array of the specified types for all objects (String elementb:newstr) {System.out.print (Elementb + "");
} System.out.println ();
Add an element to the array public static void Testc () {String [] str = {"Java", "C + +", "Php", "C #", "Python"};
for (String elementa:str) {System.out.print (Elementa + "");
}//Add ruby list<string> List = new arraylist<string> ();
for (int i=0; i<str.length; i++) {list.add (str[i]); } list.add (2, "Ruby");
List.add ("Ruby") System.out.println (); string[] Newstr = List.toarray (New STRING[1]);
Returns an array of the specified types for all objects (String elementb:newstr) {System.out.print (Elementb + "");
} System.out.println (); }
}
Console results:
The above Java array, remove duplicate values, add, delete the array elements of the implementation method is small series to share all the content, hope to give you a reference, but also hope that we support cloud habitat community.