Back to articles
ArrayList Scenario Based Questions(Java)

ArrayList Scenario Based Questions(Java)

via Dev.toKavitha

1.Movie list in OTT app User scrolls movies → mostly reading Program: package Arraylist ; import java.util.ArrayList ; public class movie { public static void main ( String [] args ) { ArrayList < String > movies = new ArrayList <>(); movies . add ( "Leo" ); movies . add ( "Vikram" ); movies . add ( "Youth" ); try { System . out . println ( movies . get ( 0 )); System . out . println ( movies . get ( 1 )); System . out . println ( movies . get ( 2 )); System . out . println ( movies . get ( 3 )); } catch ( IndexOutOfBoundsException e ) { System . out . println ( "Error!Out of index" ); } } } Output: Leo Vikram Youth Error!Out of index 2.Product catalog in e-commerce Products displayed, accessed by index → fast retrieval needed. Program: package Arraylist ; import java.util.ArrayList ; public class website { public static void main ( String [] args ) { ArrayList < String > products = new ArrayList <>(); products . add ( "Laptop" ); products . add ( "Mobile" ); products . add ( "Headphon

Continue reading on Dev.to

Opens in a new tab

Read Full Article
7 views

Related Articles