Professional Documents
Culture Documents
If you try and put a value larger than the maximum value in Java, or a value
smaller than the minimum value in Java, then you will get an Overflow in the case of
the maximum value or an Underflow in the case of the minimum.
if in line
variabila = conditie ? prima varianta ? a doua varianta
JAVA OPERATOR PRECEDENCE TABLE
Copierea vectorilor
Reverse vector :
Sortarea vectorilor
java.util.Arrays.sort(c);
Exista trei tipuri de date din limbajul C care nu sunt suportate de limbajul Java.
Acestea sunt: pointer, struct ¸si union. Pointerii au fost eliminati din cauza ca erau o
sursa constanta de erori, locul lor fiind luat de tipul referinta, iar struct si union nu isi
mai au rostul atat timp cat tipurile compuse de date sunt formate in Java prin
intermediul claselor.
int x = 1;
System.out.println(++x);
// operatorul de incrementare prefixat 2
int y = 1;
System.out.println(y++);
// operatorul de incrementare postfixat 1
int a = 1;
System.out.println(--a);
// operatorul de incrementare prefixat 0
int b = 1;
System.out.println(b--);
// operatorul de decrementare postfixat 1
System.out.println(b);
MODIFICATORI DE ACCES
• public In orice alta clasa se pot crea instante ale clasei respective.
• private In nici o alta clasa nu se pot instantia obiecte ale acestei clase. O astfel
de clasa poate contine metode publice (numite ”factory methods”) care sa fie
responsabile cu crearea obiectelor, controland in felul acesta diverse aspecte legate de
instantierea clasei respective.
• implicit Doar in clasele din acelasi pachet se pot crea instante ale clasei
respective.
•transient Este folosit la serializarea obiectelor, pentru a specifica ce variabile
membre ale unui obiect nu participa la serializare. (vezi ”Serializarea obiectelor”)
OVERLOADING (SUPRAINCARCARE)
Factory - Clasa care folosește aceste subclase nu trebuie să “știe” tipul lor concret
ci doar pe al părintelui.
charAt(int index)
char
Returns the char value at the specified index.
codePointAt(int index)
int Returns the character (Unicode code point) at the specified
index.
codePointBefore(int index)
int Returns the character (Unicode code point) before the
specified index.
compareTo(String anotherString)
int
Compares two strings lexicographically.
compareToIgnoreCase(String str)
int Compares two strings lexicographically, ignoring case
differences.
concat(String str)
String
Concatenates the specified string to the end of this string.
contains(CharSequence s)
boolean Returns true if and only if this string contains the specified
sequence of char values.
contentEquals(CharSequence cs)
boolean
Compares this string to the specified CharSequence.
contentEquals(StringBuffer sb)
boolean
Compares this string to the specified StringBuffer.
copyValueOf(char[] data)
static String
Equivalent to valueOf(char[]).
endsWith(String suffix)
boolean
Tests if this string ends with the specified suffix.
equals(Object anObject)
boolean
Compares this string to the specified object.
equalsIgnoreCase(String anotherString)
boolean Compares this String to another String, ignoring case
considerations.
getBytes()
getBytes(Charset charset)
byte[] Encodes this String into a sequence of bytes using the
given charset, storing the result into a new byte array.
getBytes(String charsetName)
byte[] Encodes this String into a sequence of bytes using the
named charset, storing the result into a new byte array.
hashCode()
int
Returns a hash code for this string.
indexOf(int ch)
int Returns the index within this string of the first occurrence
of the specified character.
indexOf(String str)
int Returns the index within this string of the first occurrence
of the specified substring.
indexOf(String str, int fromIndex)
Returns the index within this string of the first occurrence
int of the specified substring, starting at the specified index.
intern()
String
Returns a canonical representation for the string object.
isEmpty()
boolean
Returns true if, and only if, length() is 0.
lastIndexOf(int ch)
int Returns the index within this string of the last occurrence of
the specified character.
lastIndexOf(String str)
int Returns the index within this string of the last occurrence of
the specified substring.
length()
int
Returns the length of this string.
matches(String regex)
boolean Tells whether or not this string matches the given regular
expression.
regionMatches(boolean ignoreCase,
boolean int toffset, String other, int ooffset, int len)
Tests if two string regions are equal.
regionMatches(int toffset, String other,
boolean int ooffset, int len)
Tests if two string regions are equal.
split(String regex)
String[] Splits this string around matches of the given regular
expression.
startsWith(String prefix)
boolean
Tests if this string starts with the specified prefix.
substring(int beginIndex)
String
Returns a string that is a substring of this string.
toCharArray()
char[]
Converts this string to a new character array.
toLowerCase()
Converts all of the characters in this String to lower case
String
using the rules of the default locale.
toLowerCase(Locale locale)
Converts all of the characters in this String to lower case
String
using the rules of the given Locale.
toString()
String
This object (which is already a string!) is itself returned.
toUpperCase()
String Converts all of the characters in this String to upper case
using the rules of the default locale.
toUpperCase(Locale locale)
String Converts all of the characters in this String to upper case
using the rules of the given Locale.
trim()
String Returns a string whose value is this string, with any leading
and trailing whitespace removed.
valueOf(boolean b)
static String
Returns the string representation of the boolean argument.
valueOf(char c)
static String
Returns the string representation of the char argument.
valueOf(char[] data)
static String Returns the string representation of the char array
argument.
valueOf(double d)
static String
Returns the string representation of the double argument.
valueOf(float f)
static String
Returns the string representation of the float argument.
valueOf(int i)
static String
Returns the string representation of the int argument.
valueOf(long l)
static String
Returns the string representation of the long argument.
valueOf(Object obj)
static String
Returns the string representation of the Object argument.
a) Uppercase doar prima litera dintr-un cuvant:
int n = scanner.nextInt();
String s = Integer.toString(n);
java end-of-file
for (int i = 0; scanner.hasNext(); i++) {
System.out.println(i + " " + scanner.nextLine());
}
// neordonat nesortat
HashSet<String> list = new HashSet<>();
list.add("one");
list.add("five");
list.add("two");
list.add("four");
list.add("two");
list.add("three");
System.out.println(list);
// ordonat
LinkedHashSet<String> list = new LinkedHashSet<>();
list.add("one");
list.add("five");
list.add("two");
list.add("four");
list.add("two");
list.add("three");
System.out.println(list);
// Neordonat Nesortat
HashMap<String, String> list = new HashMap<>();
list.put("key1", "one");
list.put("key3", "three");
list.put("key5", "five");
list.put("key2", "two");
list.put("key2", "two");
list.put("key4", "four");
System.out.println(list);
// Ordonat
LinkedHashMap<String, String> list = new LinkedHashMap<>();
list.put("key1", "one");
list.put("key3", "three");
list.put("key5", "five");
list.put("key2", "two");
list.put("key2", "two");
list.put("key4", "four");
System.out.println(list);
// sortat crescator