Java Ignore Case

      String Str1 = new String("This is really not immutable!!");
      String Str2 = Str1;
      String Str3 = new String("This is really not immutable!!");
      String Str4 = new String("This IS REALLY NOT IMMUTABLE!!");
      boolean retVal;

      retVal = Str1.equals( Str2 );
      System.out.println("Returned Value = " + retVal );

      retVal = Str1.equals( Str3 );
      System.out.println("Returned Value = " + retVal );

      retVal = Str1.equalsIgnoreCase( Str4 );
      System.out.println("Returned Value = " + retVal );

This will produce the following result −

Output

Returned Value = true
Returned Value = true
Returned Value = true

https://www.tutorialspoint.com/java/java_string_equalsignorecase.htm

Advertisements
Posted in Compus | Tagged

Java Integrer to String Examples

 

Convert using Integer.toString(int)

The Integer class has a static method that returns a String object representing the specified int parameter. Using this is an efficient solution.

Syntax

public static String toString(int i)

The argument i is converted and returned as a string instance. If the number is negative, the sign will be preserved.

Example

int number = -782;
String numberAsString = Integer.toString(number);

The code is equivalent to:

String numberAsString = "-782";

If you will try and search for solutions, this is one of the most popular ways of converting an int to String.

Convert using String.valueOf(int)

The String class has several static methods that can convert most primitive types to their String representation. This includes integers.

Example

int number = -782;
String numberAsString = String.valueOf(number);

or

String numberAsString = String.valueOf(-782);

This is also an efficient solution like the first option above. And because this is simple and efficient, it is also a very popular method for converting an int to String.

 

http://javadevnotes.com/java-integer-to-string-examples

Posted in Compus, General | Tagged

String types

2.1  String Literal vs. String Object

OOP_StringLliteralVsObject.png

As mentioned, there are two ways to construct a string: implicit construction by assigning a string literal or explicitly creating a String object via the new operator and constructor. For example,

String s1 = "Hello";              // String literal
String s2 = "Hello";              // String literal
String s3 = s1;                   // same reference
String s4 = new String("Hello");  // String object
String s5 = new String("Hello");  // String object

Java has provided a special mechanism for keeping the String literals – in a so-called string common pool. If two string literals have the same contents, they will share the same storage inside the common pool. This approach is adopted to conserve storage for frequently-used strings. On the other hand, String objects created via the new operator and constructor are kept in the heap. Each String object in the heap has its own storage just like any other object. There is no sharing of storage in heap even if two String objects have the same contents.

You can use the method equals() of the String class to compare the contents of two Strings. You can use the relational equality operator '==' to compare the references (or pointers) of two objects. Study the following codes:

s1 == s1;         // true, same pointer
s1 == s2;         // true, s1 and s1 share storage in common pool
s1 == s3;         // true, s3 is assigned same pointer as s1
s1.equals(s3);    // true, same contents
s1 == s4;         // false, different pointers
s1.equals(s4);    // true, same contents
s4 == s5;         // false, different pointers in heap
s4.equals(s5);    // true, same contents

Important Notes:

  • In the above example, I used relational equality operator '==' to compare the references of two String objects. This is done to demonstrate the differences between string literals sharing storage in the common pool and String objects created in the heap. It is a logical error to use (str1 == str2) in your program to compare the contents of two Strings.
  • String can be created by directly assigning a String literal which is shared in a common pool. It is uncommon and not recommended to use the new operator to construct a String object in the heap.

[TODO] Explain the method String.intern().

 

https://www.ntu.edu.sg/home/ehchua/programming/java/J3d_String.html

Posted in Compus | Tagged

Java convert String to Int

In Java, you can use Integer.parseInt() to convert a String to int.

1. Integer.parseInt() Examples

Example to convert a String “10” to an primitive int.

String number = "10";
int result = Integer.parseInt(number);
System.out.println(result);

Output

10

2. Integer.valueOf() Examples

Alternatively, you can use Integer.valueOf(), it will returns an Integer object.

String number = "10";
Integer result = Integer.valueOf(number);
System.out.println(result);

Output

10
Note
In summary, parseInt(String) returns a primitive int, whereas valueOf(String) returns a new Integer() object.
Fuente: https://www.mkyong.com/java/java-convert-string-to-int/
Posted in Compus, General | Tagged

Talend Merge Files into one

http://www.deepinopensource.com/talend-merge-multiple-files-into-single-file/

Posted in Compus | Tagged

How to remove first, last or certain characters from text in Excel?

Remove the first four characters from the text string.Step 1. Type the following formula in adjacent cell B1: =RIGHT(A1, LEN(A1)-4),

Source: How to remove first, last or certain characters from text in Excel?

Posted in Compus | Tagged

Ejemplo de data quality con Talend

TFuzzyMatch :D

Ejemplo de data quality con Talend

Source: Ejemplo de data quality con Talend

Posted in Compus | Tagged , , ,