Guest User

Untitled

a guest
Jul 16th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class Diamond6 {
  4. public static void main(String[] args) {
  5. List<String> grandchild1 = Arrays.asList("A-1", "A-2", "A-3");
  6. List<String> grandchild2 = Arrays.asList("B-1", "B-2", "B-3");
  7. List<String> grandchild3 = Arrays.asList("C-1", "C-2", "C-3");
  8.  
  9. Map<Integer, List<String>> child1 = new HashMap<Integer, List<String>>();
  10. child1.put(1, grandchild1);
  11. child1.put(2, grandchild2);
  12.  
  13. Map<Integer, List<String>> child2 = new HashMap<Integer, List<String>>();
  14. child2.put(3, grandchild3);
  15.  
  16. Map<String, Map<Integer, List<String>>> data = new HashMap<String, Map<Integer, List<String>>>();
  17. data.put("Child1", child1);
  18. data.put("Child2", child2);
  19.  
  20. System.out.println(data);
  21. }
  22. }
  23. import java.util.*;
  24.  
  25. class Diamond7 {
  26. public static void main(String[] args) {
  27. List<String> grandchild1 = Arrays.asList("A-1", "A-2", "A-3");
  28. List<String> grandchild2 = Arrays.asList("B-1", "B-2", "B-3");
  29. List<String> grandchild3 = Arrays.asList("C-1", "C-2", "C-3");
  30.  
  31. Map<Integer, List<String>> child1 = new HashMap<>();
  32. child1.put(1, grandchild1);
  33. child1.put(2, grandchild2);
  34.  
  35. Map<Integer, List<String>> child2 = new HashMap<>();
  36. child2.put(3, grandchild3);
  37.  
  38. Map<String, Map<Integer, List<String>>> data = new HashMap<>();
  39. data.put("Child1", child1);
  40. data.put("Child2", child2);
  41.  
  42. System.out.println(data);
  43. }
  44. }
  45. import java.io.*;
  46.  
  47. class FileCopy6 {
  48. public static void main(String[] args) throws Exception {
  49. BufferedInputStream is = null;
  50. BufferedOutputStream os = null;
  51. try {
  52. is = new BufferedInputStream( new FileInputStream(new File("/tmp/hoge")));
  53. os = new BufferedOutputStream(new FileOutputStream(new File("/tmp/foo")));
  54. int length = 0;
  55. byte[] buffer = new byte[1024];
  56. while ((length = is.read(buffer)) >= 0) {
  57. System.out.write(buffer, 0, length);
  58. os.write(buffer, 0, length);
  59. }
  60. } finally {
  61. try { if (is != null) is.close(); } catch (IOException e) { /* ignored */ }
  62. try { if (os != null) os.close(); } catch (IOException e) { /* ignored */ }
  63. }
  64. System.out.println("Done.");
  65. }
  66. }
  67. import java.io.*;
  68.  
  69. class FileCopy7 {
  70. public static void main(String[] args) throws Exception {
  71. try (BufferedInputStream is = new BufferedInputStream( new FileInputStream(new File("/tmp/hoge")));
  72. BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(new File("/tmp/foo")))) {
  73. int length = 0;
  74. byte[] buffer = new byte[1024];
  75. while ((length = is.read(buffer)) >= 0) {
  76. System.out.write(buffer, 0, length);
  77. os.write(buffer, 0, length);
  78. }
  79. }
  80. System.out.println("Done.");
  81. }
  82. }
Add Comment
Please, Sign In to add comment