From 66c5065c2d43611178697cd921a0fecf882be733 Mon Sep 17 00:00:00 2001 From: codewithkanhaiya <89131687+codewithkanhaiya@users.noreply.github.com> Date: Mon, 31 Oct 2022 00:37:25 +0530 Subject: [PATCH] adding the value in a list.java --- Java/adding the value in a list.java | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 Java/adding the value in a list.java diff --git a/Java/adding the value in a list.java b/Java/adding the value in a list.java new file mode 100644 index 0000000..509bc52 --- /dev/null +++ b/Java/adding the value in a list.java @@ -0,0 +1,58 @@ +package com.company; + +import java.util.ArrayList; +import java.util.Scanner; + + +class MyGeneric{ + int val; + private T1 t1; + private T2 t2; + + public MyGeneric(int val, T1 t1, T2 t2) { + this.val = val; + this.t1 = t1; + this.t2= t2; + } + + public T2 getT2() { + return t2; + } + + public void setT2(T2 t2) { + this.t2 = t2; + } + + public int getVal() { + return val; + } + + public void setVal(int val) { + this.val = val; + } + + public T1 getT1() { + return t1; + } + + public void setT1(T1 t1) { + this.t1 = t1; + } +} +public class cwh_110_generics { + public static void main(String[] args) { + ArrayList arrayList = new ArrayList(); +// ArrayList arrayList = new ArrayList(); -- this will produce an error +// arrayList.add("str1"); + arrayList.add(54); + arrayList.add(643); +// arrayList.add(new Scanner(System.in)); + + int a = (int) arrayList.get(0); +// System.out.println(a); + MyGeneric g1 = new MyGeneric(23, "MyString is my string ", 45); + String str = g1.getT1(); + Integer int1 = g1.getT2(); + System.out.println(str + int1); + } +}