How to implement a simple array by java
This article focuses on "how to implement a simple array in java". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to implement a simple array with java.
Package com.clean.array;public class HighArray {private long [] array; private int nElems; public HighArray (int max) {array = new long [max]; nElems = 0;} public boolean find (long key) {int j; for (j = 0; j < nElems; j + +) {if (array [j] = = key) {break } if (j = = nElems) {return false;} else {return true;}} public void insert (long value) {array [nElems] = value; nElems + +;} public boolean delete (long value) {int j; for (j = 0; j < nElems) J + +) {if (value = = array [j]) {break;}} if (j = = nElems) {return false;} else {for (int k = j; k < nElems; k + +) {array [k] = array [k + 1];} nElems-- Return true;}} public void disPlay () {for (int j = 0; j < nElems; j + +) {System.out.print (Array [j] + ");} System.out.println ();}} package com.clean.array;public class HighArrayApp {public static void main (String [] args) {int max = 100 HighArray highArray = new HighArray (max); highArray.insert; highArray.insert (60); highArray.insert (11); highArray.disPlay (); long key = 1100 / long key If (highArray.find (key)) {System.out.println ("find key =" + key);} else {System.out.println ("can not find the key:" + key);} highArray.delete (100); highArray.delete (11); highArray.disPlay () }} at this point, I believe you have a deeper understanding of "how to implement a simple array in java". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!