How to hack a Java array

Source: Internet
Author: User

Importjava.util.List; Importjava.util.ArrayList; ImportJava.util.Set; ImportJava.util.HashSet;  Public classLzwcode { Public Static voidmain (String [] args) {TestA (); System.out.println ("===========================");          Testb (); System.out.println ("===========================");      TESTC (); }        //remove duplicate values from the array     Public Static voidTestA () {String [] str= {"Java", "C + +", "Php", "C #", "Python", "C + +", "Java"};  for(String elementa:str) {System.out.print (Elementa+ " "); } List<String> list =NewArraylist<string>();  for(inti=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 (NewSTRING[1]);//returns an array containing the specified type of all objects         for(String elementb:newstr) {System.out.print (Elementb+ " ");      } System.out.println (); }        //Delete One of the elements in an array     Public Static voidTestb () {String [] str= {"Java", "C + +", "Php", "C #", "Python"};  for(String elementa:str) {System.out.print (Elementa+ " "); }          //Remove PHPlist<string> list =NewArraylist<string>();  for(inti=0; i<str.length; i++) {List.add (str[i]); } list.remove (2);//list.remove ("Php")System.out.println (); String[] Newstr= List.toarray (NewSTRING[1]);//returns an array containing the specified type of all objects         for(String elementb:newstr) {System.out.print (Elementb+ " ");      } System.out.println (); }        //add an element to an array     Public Static voidTESTC () {String [] str= {"Java", "C + +", "Php", "C #", "Python"};  for(String elementa:str) {System.out.print (Elementa+ " "); }          //Add Rubylist<string> list =NewArraylist<string>();  for(inti=0; i<str.length; i++) {List.add (str[i]); } list.add (2, "Ruby");//list.add ("Ruby")System.out.println (); String[] Newstr= List.toarray (NewSTRING[1]);//returns an array containing the specified type of all objects         for(String elementb:newstr) {System.out.print (Elementb+ " ");      } System.out.println (); }  } 

How to hack a Java array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.