[Solved] printing data of specific element from array in java [duplicate]


Your implementation of Clip class is wrong. It should be something like this:

public class Clip {
        private String title;
        private String author;

        public Clip(String title, String author) {
            this.title = title;
            this.author = author;
        }

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public String getAuthor() {
            return author;
        }

        public void setAuthor(String author) {
            this.author = author;
        }
    }

And you can retrieve your objects from array like this:

@Test
    public void testClipArray() throws Exception {
        // Lets assume our array contains 2 elements
        Clip[] clipArray = new Clip[2];
        clipArray[0] = new Clip("First", "Clip");
        clipArray[1] = new Clip("Second", "Clip");

        // Lets retrieve 2nd object (with index: 1)
        Clip secondObject = clipArray[1];

        System.out.println(secondObject.getAuthor());
        System.out.println(secondObject.getTitle());
    }

solved printing data of specific element from array in java [duplicate]