Python provides the tuple data structure An immutable sequen

Python provides the tuple data structure: An immutable sequence that cannot change its size or its contents after it is declared. Java, however, has no equivalent structure. Arrays have a fixed size, but their contents can be changed after creation. However, if we wrap an array in an object, we can limit how the array can be accessed. This is the approach we will use to develop our Java tuple implementation. You will extend the Abstract List class to create a class called Tuple. Specifically, you must extend AbstractList for your tuple to work properly. Read the API for AbstractList to determine what methods are necessary for an immutable subclass of Abstract List Because we are explicitly extending AbstractList , any time that you see E in the AbstractList API, you can safely say Object instead. In addition to those methods, your class must have two public constructors. The first should take no arguments and therefore produce an empty tuple. The second should take an array of Objects as its only parameter. In this constructor, you should copy the contents of the parameter array into the array underlying the tuple.

Solution

That is correct to say that tuple data structre doesn\'t have in Java..likewise they have in Python. Tuples contains number of values seperated by commas and other functions and they are immutable. You would extend the abstract class to make sure that tuple data structure is implemented.

public class Tuple {
private Object[] arr;
private int size;
private static boolean TypeLock = false;
private static Object[] lastTuple = {1,1,1}; //default tuple type
private Tuple(Object ... c) { // Extending of the abstract class of tuple from public to private
// TODO Auto-generated constructor stub
size=c.length;
arr=c;
The function such as it would take an array of objects as its only parameter.

if (p.arr[i].getClass() == this.arr[i].getClass())

{

if (!this.arr[i].equals(p.arr[i])) // Array declaration and usage of the same in the program
return false;
}
else

The contents of the parameter of the same had to be passed to the array to execute the overall functions of the program.

 Python provides the tuple data structure: An immutable sequence that cannot change its size or its contents after it is declared. Java, however, has no equival

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site