Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.82 KB | None | 0 0
  1. import java.util.ArrayList;
  2.         import java.util.List;
  3.  
  4. public class AlphabetAssociatedLists {
  5.     //List of String lists that will hold our associated lists
  6.     //Use example: List.get(int index).add(String name)//List.get(getIndex(char c)).add(String name)
  7.     //index is value of equation (for our char from char list named char c) c - 'a'
  8.     //so it's 0 for a and 25 for z
  9.     public static List<List<String>> lists;
  10.  
  11.     //Constructor, will be called when an object of our class is made with 'new' keywoard
  12.     public AlphabetAssociatedLists() {
  13.  
  14.         //Fill the main List with empty array lists
  15.         for (int i = 0; i < 26; ++i)
  16.             lists.add(new ArrayList<String>());
  17.     }
  18.  
  19.     //Gets index by the equation in line 7
  20.     public int getIndex(char c) {
  21.         return (int)c - (int)'a';
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement