Вы находитесь на странице: 1из 3

7/3/2017 Nested generic type : Generics Basics Generics Java Tutorial

Home (http://www.java2s.com) Custom Search Search


Java Tutorial
(/Tutorial/Java/CatalogJava.htm) Nested generic type : Generics
Language
(/Tutorial/Java/0020__Language/C Basics Generics Java Tutorial
atalog0020__Language.htm)
Data Type
(/Tutorial/Java/0040__Data-
Type/Catalog0040__Data-
Type.htm)
Operators
(/Tutorial/Java/0060__Operators/C Java Tutorial (/Tutorial/Java/CatalogJava.htm)
atalog0060__Operators.htm) / Generics (/Tutorial/Java/0200__Generics/Catalog0200__Generics.htm)
Statement Control / Generics Basics (/Tutorial/Java/0200__Generics/0020__Generics-Basics.htm) /
(/Tutorial/Java/0080__Statement-
Control/Catalog0080__Statement- A generic type is itself a type and can be used as a type variable. For example, if you want your
Control.htm)
List to store lists of strings:
Class Definition
(/Tutorial/Java/0100__Class-
List<List<String>> myListOfListsOfStrings;
Definition/Catalog0100__Class-
Definition.htm)
To retrieve the first string from the first list in myList, you would use:
Development
(/Tutorial/Java/0120__Developmen
String s = myListOfListsOfStrings.get(0).get(0);
t/Catalog0120__Development.htm)
Reflection
(/Tutorial/Java/0125__Reflection/C Working with List of Lists
atalog0125__Reflection.htm)
import java.util.ArrayList;
Regular Expressions
import java.util.List;
(/Tutorial/Java/0130__Regular-
Expressions/Catalog0130__Regula
public class MainClass {
r-Expressions.htm) public static void main(String[] args) {
Collections List<String> listOfStrings = new ArrayList<String>();
(/Tutorial/Java/0140__Collections/ listOfStrings.add("Hello again");
Catalog0140__Collections.htm) List<List<String>> listOfLists = new ArrayList<List<String>>();
Thread listOfLists.add(listOfStrings);
(/Tutorial/Java/0160__Thread/Catal String s = listOfLists.get(0).get(0);
System.out.println(s); // prints "Hello again"
og0160__Thread.htm)
}
File
}
(/Tutorial/Java/0180__File/Catalog
0180__File.htm)
Generics ()
I18N
(/Tutorial/Java/0220__I18N/Catalo
g0220__I18N.htm)
Swing
(/Tutorial/Java/0240__Swing/Catal
og0240__Swing.htm)
Swing Event
(/Tutorial/Java/0260__Swing-
Event/Catalog0260__Swing- 12.1.Generics Basics
Event.htm)
2D Graphics 12.1.1. Life without Generics (/Tutorial/Java/0200__Generics/LifewithoutGenerics.htm)
(/Tutorial/Java/0261__2D-
12.1.2. What Are Generics? A Simple Generics Example
Graphics/Catalog0261__2D-
(/Tutorial/Java/0200__Generics/WhatAreGenericsASimpleGenericsExample.htm)
Graphics.htm)
SWT
12.1.3. Generics Work Only with Objects
(/Tutorial/Java/0280__SWT/Catalo
(/Tutorial/Java/0200__Generics/GenericsWorkOnlywithObjects.htm)
g0280__SWT.htm)
SWT 2D Graphics 12.1.4. A Generic Class with Two Type Parameters
(/Tutorial/Java/0300__SWT-2D- (/Tutorial/Java/0200__Generics/AGenericClasswithTwoTypeParameters.htm)
Graphics/Catalog0300__SWT-2D-
Graphics.htm) 12.1.5. Introducing Generic Types (/Tutorial/Java/0200__Generics/IntroducingGenericTypes.htm)
Network
(/Tutorial/Java/0320__Network/Cat 12.1.6. Working with generic List (/Tutorial/Java/0200__Generics/WorkingwithgenericList.htm)
alog0320__Network.htm)

http://www.java2s.com/Tutorial/Java/0200__Generics/Nestedgenerictype.htm 1/3
7/3/2017 Nested generic type : Generics Basics Generics Java Tutorial
Database
12.1.7. Nested generic type
(/Tutorial/Java/0340__Database/C
atalog0340__Database.htm) 12.1.8. A generic type can accept more than one type variables.
Hibernate (/Tutorial/Java/0200__Generics/Agenerictypecanacceptmorethanonetypevariables.htm)
(/Tutorial/Java/0350__Hibernate/C
atalog0350__Hibernate.htm) 12.1.9. Raw Types and Legacy Code (/Tutorial/Java/0200__Generics/RawTypesandLegacyCode.htm)
JPA
(/Tutorial/Java/0355__JPA/Catalog
0355__JPA.htm)
JSP
(/Tutorial/Java/0360__JSP/Catalog
0360__JSP.htm)
JSTL
(/Tutorial/Java/0380__JSTL/Catalo
g0380__JSTL.htm)
Servlet
(/Tutorial/Java/0400__Servlet/Catal
og0400__Servlet.htm)
Web Services SOA
(/Tutorial/Java/0410__Web-
Services-SOA/Catalog0410__Web-
Services-SOA.htm)
EJB3
(/Tutorial/Java/0415__EJB3/Catalo
g0415__EJB3.htm)
Spring
(/Tutorial/Java/0417__Spring/Catal
og0417__Spring.htm)
PDF
(/Tutorial/Java/0419__PDF/Catalog
0419__PDF.htm)
Email
(/Tutorial/Java/0420__Email/Catalo
g0420__Email.htm)
J2ME
(/Tutorial/Java/0430__J2ME/Catalo
g0430__J2ME.htm)
J2EE Application
(/Tutorial/Java/0440__J2EE-
Application/Catalog0440__J2EE-
Application.htm)
XML
(/Tutorial/Java/0440__XML/Catalog
0440__XML.htm)
Design Pattern
(/Tutorial/Java/0460__Design-
Pattern/Catalog0460__Design-
Pattern.htm)
Log
(/Tutorial/Java/0480__Log/Catalog
0480__Log.htm)
Security
(/Tutorial/Java/0490__Security/Cat
alog0490__Security.htm)
Apache Common
(/Tutorial/Java/0500__Apache-
Common/Catalog0500__Apache-
Common.htm)
Ant
(/Tutorial/Java/0520__Ant/Catalog0
520__Ant.htm)
JUnit
(/Tutorial/Java/0540__JUnit/Catalo
g0540__JUnit.htm)
java2s.com (http://www.java2s.com/) | Email:info at java2s.com | Demo Source and Support. All rights reserved.

http://www.java2s.com/Tutorial/Java/0200__Generics/Nestedgenerictype.htm 2/3
7/3/2017 Nested generic type : Generics Basics Generics Java Tutorial

http://www.java2s.com/Tutorial/Java/0200__Generics/Nestedgenerictype.htm 3/3

Вам также может понравиться