This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.time.LocalDate; | |
| public class Main { | |
| public static void main(String[] args) { | |
| String str = "2016-03-26"; | |
| LocalDate date = LocalDate.parse(str); | |
| // if format of string is default date format, | |
| // we can convert in one step. | |
| System.out.println(date); // 2016-03-26 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.time.LocalDate; | |
| import java.time.Month; | |
| import java.time.format.DateTimeFormatter; | |
| public class Main { | |
| public static void main(String[] args) { | |
| LocalDate date = LocalDate.of(2018, Month.MAY, 26); | |
| System.out.println(date); // 2018-05-26 | |
| DateTimeFormatter f = DateTimeFormatter.ofPattern("dd MMM, YYYY"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.time.LocalDate; | |
| import java.time.Month; | |
| public class Main { | |
| public static void main(String[] args) { | |
| LocalDate date = LocalDate.of(2018, Month.MAY, 26); | |
| System.out.println(date); // 2018-05-26 | |
| date = date.plusYears(2); | |
| System.out.println(date); // 2020-05-26 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.time.LocalDate; | |
| import java.time.Month; | |
| public class Main { | |
| public static void main(String[] args) { | |
| LocalDate date = LocalDate.of(2018, Month.MAY, 26); | |
| System.out.println(date); // 2018-05-26 | |
| System.out.println("Year: " + date.getYear()); // Year: 2018 | |
| System.out.println("Month: " + date.getMonth()); // Month: MAY |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.time.LocalDate; | |
| import java.time.Month; | |
| public class Main { | |
| public static void main(String[] args) { | |
| LocalDate date = LocalDate.of(2018, 5, 26); | |
| System.out.println(date); // 2018-05-26 | |
| // or |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.time.LocalDate; | |
| public class Main { | |
| public static void main(String[] args) { | |
| LocalDate date = LocalDate.now(); | |
| System.out.println(date); // 2021-08-16(current date) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Main { | |
| public static void main(String[] args) { | |
| // K , V | |
| Map<String, Double> fruit = new HashMap<>(); | |
| fruit.put("Orange", 1.05); | |
| fruit.put("Mango", 0.50); | |
| fruit.put("Apple", 0.76); | |
| fruit.put("Lemon", 1.47); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.LinkedList; | |
| import java.util.Queue; | |
| import java.util.Stack; | |
| public class Main { | |
| public static void main(String[] args) { | |
| // Queue - FIFO (First In, First Out) | |
| // LinkedList is one of the Queue implementations as well | |
| Queue<String> queueInStore = new LinkedList<>(); | |
| queueInStore.add("Alex"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.*; | |
| public class Main { | |
| public static void main(String[] args) { | |
| Set<String> cars = new HashSet<>(); | |
| cars.add("honda"); | |
| cars.add("audi"); | |
| cars.add("bmw"); | |
| cars.add("tesla"); | |
| cars.add("bmw"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.util.List; | |
| import java.util.ArrayList; | |
| public class Main { | |
| public static void main(String[] args) { | |
| // create list of String | |
| List<String> cars = new ArrayList<>(); | |
| // add elements to back of the list | |
| cars.add("bmw"); |