programming:java:java
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| programming:java:java [2023/11/02 13:56] – [Regular Expressions (java.util.regex)] skipidar | programming:java:java [2023/11/02 14:33] (current) – [Records] skipidar | ||
|---|---|---|---|
| Line 1128: | Line 1128: | ||
| \z The end of the input | \z The end of the input | ||
| </ | </ | ||
| + | |||
| + | |||
| + | ==== Tokenize strings ==== | ||
| + | |||
| + | Break into single words. | ||
| + | |||
| + | <sxh java> | ||
| + | |||
| + | String[] result = "this is a test" | ||
| + | for (int x=0; x< | ||
| + | System.out.println(result[x]); | ||
| + | |||
| + | /* this | ||
| + | is | ||
| + | a | ||
| + | test | ||
| + | */ | ||
| + | |||
| + | </ | ||
| Line 1151: | Line 1170: | ||
| </ | </ | ||
| + | ==== ReplaceAll | ||
| + | <sxh java> | ||
| + | @Test | ||
| + | void stringReplaceAll() { | ||
| + | String s = "bob and alice like to text each other"; | ||
| + | String john = s.replaceAll(" | ||
| + | System.out.println(john); | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | ===== Records ===== | ||
| + | First: Java 14 | ||
| + | |||
| + | |||
| + | |||
| + | <sxh java> | ||
| + | // some interface | ||
| + | interface MyBarkInterface{ | ||
| + | default void bark(){ | ||
| + | System.out.println(" | ||
| + | } | ||
| + | } | ||
| + | |||
| + | record MyPoint(int x, int y) implements MyBarkInterface{}; | ||
| + | |||
| + | // Cant inherit from Record - its final | ||
| + | //record MyPoint2(int x, int y) extends MyPoint{}; | ||
| + | |||
| + | |||
| + | @Test | ||
| + | void recordTest1() { | ||
| + | MyPoint p = new MyPoint(1, | ||
| + | |||
| + | System.out.println(p); | ||
| + | System.out.println(p.x()); | ||
| + | System.out.println(p.x()); | ||
| + | | ||
| + | p.bark(); // can access hiearchy | ||
| + | } | ||
| + | |||
| + | </ | ||
programming/java/java.1698933419.txt.gz · Last modified: by skipidar
