<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lương Quốc Tây</title>
    <description>The latest articles on DEV Community by Lương Quốc Tây (@tayjava).</description>
    <link>https://dev.to/tayjava</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4027722%2F03f64d41-b3fe-4b40-a1fd-7023f0143c1f.jpg</url>
      <title>DEV Community: Lương Quốc Tây</title>
      <link>https://dev.to/tayjava</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tayjava"/>
    <language>en</language>
    <item>
      <title>Top 10 Java Questions on Strings and Arrays</title>
      <dc:creator>Lương Quốc Tây</dc:creator>
      <pubDate>Mon, 13 Jul 2026 19:17:04 +0000</pubDate>
      <link>https://dev.to/tayjava/top-10-java-questions-on-strings-and-arrays-5d9m</link>
      <guid>https://dev.to/tayjava/top-10-java-questions-on-strings-and-arrays-5d9m</guid>
      <description>&lt;ol&gt;
&lt;li&gt;&lt;p&gt;What is the difference between String, StringBuilder, and StringBuffer?&lt;br&gt;
📌 Answer:&lt;br&gt;
• String: Immutable. Every modification creates a new object in memory.&lt;br&gt;
• StringBuilder: Mutable, fast, and not thread-safe.&lt;br&gt;
• StringBuffer: Mutable and thread-safe (synchronized), but slower than StringBuilder due to synchronization overhead.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Why is String in Java immutable?&lt;br&gt;
📌 Answer:&lt;br&gt;
• Security: Strings are frequently used as parameters for network connections, URLs, and class loaders. Immutability prevents malicious alteration.&lt;br&gt;
• Efficient Hashing: The hash code is cached upon creation, making Strings highly efficient and safe to use as keys in HashMap or elements in HashSet.&lt;br&gt;
• Thread-Safety: Multiple threads can safely share the same String instance without the need for synchronization.&lt;br&gt;
• String Pool Support: Enables memory savings by allowing the JVM to reuse existing instances from the String constant pool.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What is the String pool in Java?&lt;br&gt;
📌 Answer:&lt;br&gt;
• It is a special memory region within the heap used to store String literals.&lt;br&gt;
• When creating a string like "hello", the JVM first checks the pool. If the string already exists, it reuses the existing reference instead of creating a new object.&lt;br&gt;
• The intern() method can be used to manually add a String object to the pool.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What is the difference between == and .equals() when comparing Strings?&lt;br&gt;
📌 Answer:&lt;br&gt;
• ==: Compares object references (memory addresses).&lt;br&gt;
• .equals(): Compares the actual content (character sequence) of the Strings.&lt;br&gt;
&lt;code&gt;String a = "abc";&lt;br&gt;
String b = new String("abc");&lt;br&gt;
System.out.println(a == b);       // false (different memory addresses)&lt;br&gt;
System.out.println(a.equals(b));  // true (same content)&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do you reverse a String in Java?&lt;br&gt;
📌 Answer:&lt;br&gt;
• Using StringBuilder (Recommended):&lt;br&gt;
&lt;code&gt;String s = "Java";&lt;br&gt;
String reversed = new StringBuilder(s).reverse().toString();&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do you check if a string is a palindrome?&lt;br&gt;
📌 Answer:&lt;br&gt;
• A palindrome is a string that reads the same forward and backward.&lt;br&gt;
&lt;code&gt;String s = "madam";&lt;br&gt;
boolean isPalindrome = s.equals(new StringBuilder(s).reverse().toString());&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do you convert a String to a character array (char[])?&lt;br&gt;
📌 Answer:&lt;br&gt;
• By using the toCharArray() method:&lt;br&gt;
&lt;code&gt;String s = "hello";&lt;br&gt;
char[] arr = s.toCharArray();&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do you find the largest element in an integer array?&lt;br&gt;
📌 Answer: Iterate through the array while keeping track of the maximum value:&lt;br&gt;
&lt;code&gt;int[] arr = {5, 9, 2, 7};&lt;br&gt;
int max = arr[0];&lt;br&gt;
for (int i = 1; i &amp;lt; arr.length; i++) {&lt;br&gt;
if (arr[i] &amp;gt; max) {&lt;br&gt;
    max = arr[i];&lt;br&gt;
}&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How do you sort an array in Java?&lt;br&gt;
📌 Answer:&lt;br&gt;
• For primitive or object arrays, use the built-in method: Arrays.sort(arr);&lt;br&gt;
• For object arrays, you can use a custom comparator (e.g., to sort in descending order):&lt;br&gt;
&lt;code&gt;// Note: 'arr' must be an array of objects (e.g., Integer[]), not primitives (int[])&lt;br&gt;
Arrays.sort(arr, (a, b) -&amp;gt; b - a); // sorts in descending order&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What is the difference between an Array and an ArrayList in Java? &lt;br&gt;
📌 Answer:&lt;br&gt;
• Array:&lt;br&gt;
    ◦ Fixed size (cannot be resized after creation).&lt;br&gt;
    ◦ Can contain both primitive types (e.g., int, char) and objects.&lt;br&gt;
• ArrayList:&lt;br&gt;
    ◦ Dynamic size (automatically resizes as elements are added or removed).&lt;br&gt;
    ◦ Can only contain objects (uses wrapper classes like Integer or Character for primitives).&lt;br&gt;
    ◦ Provides a rich set of utility methods: add(), remove(), contains(), etc.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
    </item>
  </channel>
</rss>
