Java internal class, float, arraylist, hashmap code example

Source: Internet
Author: User

Import Java. util. arraylist; <br/> Import Java. util. hashmap; <br/> Import Java. util. map; <br/> Import Java. util. vector; </P> <p> public class test {<br/> Private Static int m_inum = 0; <br/> private int mcount; </P> <p> Public test () {<br/> mcount = 0; <br/> m_inum = 0; <br/>}</P> <p> Public test (INT num) {<br/> mcount = 1; <br/> m_inum = num; <br/>}</P> <p> Public static void main (string argv []) <br/>{</P> <p> int Arr1 [] = {4, 5, 2, 1, 3, 9, 0, 7, 6, 8}; </P> <p> system. out. println ("/Nmax number in arrray arr1 is:" + maxint (arr1, arr1.length); </P> <p> test SD = new test (); </P> <p> float F21 = 3; // OK <br/> // float F1 = 3.4; // error! Type Mismatch: cannot convert from double to float <br/> float F1 = 3.4f; <br/> float F3 = 3.4f; <br/> F3 = F3 + 1; </P> <p> int I = 0; <br/> arraylist list = new arraylist (); <br/> vector v = new vector (); <br/> while (I <10) {<br/> list. add (I); <br/> list. add (I); <br/> v. add (I); <br/> I ++; <br/>}</P> <p> system. out. println ("arraylist:"); <br/> for (I = 0; I <list. size (); I ++) {<br/> system. out. P RINT (list. get (I) + ","); <br/>}</P> <p> system. out. println ("/nvector:"); <br/> for (I = 0; I <v. size (); I ++) {<br/> system. out. print (v. get (I) + ","); <br/>}</P> <p> // a class set cannot directly store basic data types such as int, Char, values such as double <br/> // arraylist <int> mylist1 = new arraylist <int> (); <br/> arraylist <int []> mylist2 = new arraylist <int []> (); <br/> arraylist <string> mylist3 = new arraylist <string> (); <br/> arraylist <Integer> mylist4 = new arraylist <integer> (); </P> <p> Map <string, string> map1 = new hashmap <string, string> (); <br/> Map <integer, string> MAP2 = new hashmap <integer, string> (); <br/> for (Int J = 0; j <10; j ++) {<br/> map2.put (J, "hello" + J); <br/>}</P> <p> system. out. println (); <br/> for (Int J = 0; j <map2.size (); j ++) {<br/> system. out. println (map2.get (j); <br/>}</P> <p> Public stri Ng tostring () <br/>{< br/> system. out. println ("BBB" + this. m_inum); </P> <p> return "Z"; <br/>}</P> <p> static void setint (int I) {<br/> I ++; <br/> system. out. println ("setint (): I =" + I); <br/>}</P> <p> // the odd number is first, even number after <br/> Public int [] Fun (INT [] ARR) {<br/> int n = arr. length; <br/> int I = 0; <br/> Int J = n-1; </P> <p> while (I <j) {<br/> If (ARR [I] % 2! = 0) {// odd number <br/> I ++; <br/>}else {// even <br/> If (ARR [J] % 2! = 0) {<br/> int temp = arr [I]; <br/> arr [I] = arr [J]; <br/> arr [J] = temp; <br/>}< br/> j --; <br/>}</P> <p> return arr; <br/>}</P> <p> Public static int maxint (INT [] arr, int N) {</P> <p> for (INT I = 1; I <n; I ++) <br/>{< br/> arr [0] = arr [I]> arr [0]? Arr [I]: arr [0]; <br/>}</P> <p> return arr [0]; <br/>}</P> <p> protected class test1 extends test {<br/> Public test1 (INT count) {<br/> setint (0 ); // The non-static internal class can access the static and non-static member functions of the external class <br/> tostring (); <br/> system. out. println ("mcount =" + mcount ); // The non-static internal class can only access non-static member variables of the external class <br/>}</P> <p> static class Test2 extends test {<br /> Public Test2 (INT count) {<br/> setint (0); // static internal classes can access static and non-static member functions of external classes <br/> tostring (); <br/> system. out. println ("m_inum =" + m_inum ); // The static internal class can only access static member variables of the external class <br/>}</P> <p >}< br/>

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.