Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Arrays;
- import java.util.Iterator;
- import java.util.stream.Stream;
- public class Main {
- public static class HeavyBox
- {
- public String id;
- public int weight;
- public HeavyBox(String id, int weight)
- {
- this.id = id;
- this.weight = weight;
- }
- public void Print()
- {
- System.out.println(id);
- System.out.println(weight + "\n");
- }
- }
- public static void main(String[] args)
- {
- HeavyBox Box1 = new HeavyBox("Тяжелый", 789);
- HeavyBox Box2 = new HeavyBox("Средний", 237);
- HeavyBox Box3 = new HeavyBox("Легкий", 34);
- ArrayList<HeavyBox> Warehouse = new ArrayList<>(Arrays.asList(Box1, Box2, Box3));
- Iterator iterator = Warehouse.iterator();
- Stream<HeavyBox> Warehouse1 = Stream.of(Box1, Box2, Box3);
- System.out.println("Способ 1:");
- for (HeavyBox Box : Warehouse) {
- Box.Print();
- }
- System.out.println("Способ 2:"); //не понял, как вывести непосредственно значения объектов
- while (iterator.hasNext()) {
- System.out.println(iterator.next());
- }
- System.out.println("\nСпособ 3:");
- Warehouse1.forEach(element -> System.out.println(element.id+ " " +element.weight));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement