Created at 4am, Jan 7
cyranodbSoftware Development
0
Introduction to Programming Using Java
GVmhEmHoZEDrtP3_TPoQ3YAgC-8kk0WmfNiR6mtL8y8
File Type
PDF
Entry Count
2608
Embed. Model
jina_embeddings_v2_base_en
Index Type
hnsw

Introduction to Programming Using Java Version 5.0, December 2006 (Version 5.0.2, with minor corrections, November 2007) David J. Eck Hobart and William Smith Colleges, David J. Eck David J. Eck Department of Mathematics and Computer Science Hobart and William Smith Colleges Geneva, NY 14456

This book covers all the essential topics in Java development. It is not just for beginners; experienced programmers can also review the chapters for a quick reference. It can be used both as an introductory programming class using Java and also as upper level class that covers GUI programming using Java.

* Constructor creates an array with an initial size of 1, * but the array size will be increased whenever a reference * is made to an array position that does not yet exist. public DynamicArrayOfInt() { data = new int; } * * * * * * * Get the value from the specified position in the array. Since all array elements are initialized to zero, when the specified position lies outside the actual physical size of the data array, a value of 0 is returned. Note that a negative value of position will still produce an ArrayIndexOutOfBoundsException. 333 334 CHAPTER 7. ARRAYS / public int get(int position) { if (position >= data.length) return 0; else return data[position]; } * * * * Store the value in the specified position in the array. The data array will increase in size to include this position, if necessary. public void put(int position, int value) {
id: e5952e0f8c8a4f454a3280c274a5acf7 - page: 349
length) { // The specified position is outside the actual size of // the data array. Double the size, or if that still does // not include the specified position, set the new size // to 2*position. int newSize = 2 * data.length; if (position >= newSize) newSize = 2 * position; int[] newData = new int[newSize]; System.arraycopy(data, 0, newData, 0, data.length); data = newData; // The following line is for demonstration purposes only !! System.out.println("Size of dynamic array increased to " + newSize); } data[position] = value; }
id: 6f227519cc510bd54587474150a11a87 - page: 350
} // end class DynamicArrayOfInt The data in a DynamicArrayOfInt object is actually stored in a regular array, but that array is discarded and replaced by a bigger array whenever necessary. If numbers is a variable of type DynamicArrayOfInt, then the command numbers.put(pos,val) stores the value val at position number pos in the dynamic array. The function numbers.get(pos) returns the value stored at position number pos. The rst example in this section used an array to store positive integers input by the user. We can rewrite that example to use a DynamicArrayOfInt. A reference to numbers[i] is replaced by numbers.get(i). The statement numbers[numCount] = num; is replaced by numbers.put(numCount,num);. Heres the program:
id: e4ba86a78584d9a3d6d6bc4ced845a9d - page: 350
int numCount; // The number of numbers stored in the array. int num; // One of the numbers input by the user. numbers = new DynamicArrayOfInt(); numCount = 0; TextIO.putln("Enter some positive integers; Enter 0 to end"); while (true) { // Get numbers and put them in the dynamic array. 7.3. DYNAMIC ARRAYS AND ARRAYLISTS TextIO.put("? "); num = TextIO.getlnInt(); if (num <= 0) break; numbers.put(numCount, num); // Store num in the dynamic array. numCount++; } TextIO.putln("\nYour numbers in reverse order are:\n"); for (int i = numCount 1; i >= 0; i--) { TextIO.putln( numbers.get(i) ); // Print the i-th number. } } // end main(); } // end class ReverseWithDynamicArray 7.3.3 ArrrayLists
id: 57a4f278ba8d44b100b043a5dc2c1f1c - page: 350
How to Retrieve?
# Search

curl -X POST "https://search.dria.co/hnsw/search" \
-H "x-api-key: <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"rerank": true, "top_n": 10, "contract_id": "GVmhEmHoZEDrtP3_TPoQ3YAgC-8kk0WmfNiR6mtL8y8", "query": "What is alexanDRIA library?"}'
        
# Query

curl -X POST "https://search.dria.co/hnsw/query" \
-H "x-api-key: <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{"vector": [0.123, 0.5236], "top_n": 10, "contract_id": "GVmhEmHoZEDrtP3_TPoQ3YAgC-8kk0WmfNiR6mtL8y8", "level": 2}'