[resolved] string comparison

[resolved] string comparison

I have the below code :
================================================================================================================
String fileName;
String delim = "-";
globalMap.put("basename",input_row.basename); //system
globalMap.put("md5",input_row.md5); //System calculated MD5
fileName = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));
String tokens[] = fileName.split(delim); //seperate by delimiter of "-"
StringBuffer sb = new StringBuffer(128); //create string buffer
for (int i = 0; i < tokens.length; i++) //iterate through filename
{
if(i ==1)
{
context.file_type = tokens; //Get file load name from filename
}
if (i == 7) //get MD5 String
{
globalMap.put("_md5", tokens.substring(0,32));
context.md5_message = (String)globalMap.get("_md5"); //assign file MD5 to context
}
}
context.basename_message = (String)globalMap.get("basename");
context.guid_message = context.basename_message.substring(25,59);
System.out.println("Assigned Contexts from received file");
System.out.println(context.guid_message); //GUID (IN FILENAME)
System.out.println(context.md5_message); //MD5 (IN FILENAME)
System.out.println(context.basename_message); //FILENAME
System.out.println(context.file_type); //TYPE OF LOAD

System.out.println("Actual Values");
System.out.println((String)globalMap.get("md5"));
System.out.println(((String)globalMap.get("tFileList_1_CURRENT_FILE")));
//(String)globalMap.get("md5") == context.md5_message
if ((String)globalMap.get("md5") == (String)context.md5_message)
{
System.out.println("ITS a MATCH");
}
else
{
System.out.println("Waaaah, waaaah , waaaahh");
}
================================================================================================================
when i compare , the 2 strings above:
if ((String)globalMap.get("md5") == (String)context.md5_message)
it never proves true:
I have pushed my results to screen :
================================================================================================================Assigned Contexts from received file
4f2c2204-9e2f-492a-9c0d-8cd6922a1e
805262c7bd389bc1d0a612f71facce6c //System.out.println(context.md5_message);

20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
EventLoad
Actual Values
805262c7bd389bc1d0a612f71facce6c //System.out.println((String)globalMap.get("md5"));
20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
Waaaah, waaaah , waaaahh
================================================================================================================
on my output the strings are the same ...
what am i missing ,

Accepted Solutions

Re: [resolved] string comparison

I have the below code :
================================================================================================================
String fileName;
String delim = "-";
globalMap.put("basename",input_row.basename); //system
globalMap.put("md5",input_row.md5); //System calculated MD5
fileName = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));
String tokens[] = fileName.split(delim); //seperate by delimiter of "-"
StringBuffer sb = new StringBuffer(128); //create string buffer
for (int i = 0; i < tokens.length; i++) //iterate through filename
{
if(i ==1)
{
context.file_type = tokens; //Get file load name from filename
}
if (i == 7) //get MD5 String
{
globalMap.put("_md5", tokens.substring(0,32));
context.md5_message = (String)globalMap.get("_md5"); //assign file MD5 to context
}
}
context.basename_message = (String)globalMap.get("basename");
context.guid_message = context.basename_message.substring(25,59);
System.out.println("Assigned Contexts from received file");
System.out.println(context.guid_message); //GUID (IN FILENAME)
System.out.println(context.md5_message); //MD5 (IN FILENAME)
System.out.println(context.basename_message); //FILENAME
System.out.println(context.file_type); //TYPE OF LOAD

System.out.println("Actual Values");
System.out.println((String)globalMap.get("md5"));
System.out.println(((String)globalMap.get("tFileList_1_CURRENT_FILE")));
//(String)globalMap.get("md5") == context.md5_message
if ((String)globalMap.get("md5") == (String)context.md5_message)
{
System.out.println("ITS a MATCH");
}
else
{
System.out.println("Waaaah, waaaah , waaaahh");
}
================================================================================================================
when i compare , the 2 strings above:
if ((String)globalMap.get("md5") == (String)context.md5_message)
it never proves true:
I have pushed my results to screen :
================================================================================================================Assigned Contexts from received file
4f2c2204-9e2f-492a-9c0d-8cd6922a1e
805262c7bd389bc1d0a612f71facce6c //System.out.println(context.md5_message);

20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
EventLoad
Actual Values
805262c7bd389bc1d0a612f71facce6c //System.out.println((String)globalMap.get("md5"));
20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
Waaaah, waaaah , waaaahh
================================================================================================================
on my output the strings are the same ...
what am i missing ,

I have use equals()

All Replies

Re: [resolved] string comparison

I have the below code :
================================================================================================================
String fileName;
String delim = "-";
globalMap.put("basename",input_row.basename); //system
globalMap.put("md5",input_row.md5); //System calculated MD5
fileName = ((String)globalMap.get("tFileList_1_CURRENT_FILE"));
String tokens[] = fileName.split(delim); //seperate by delimiter of "-"
StringBuffer sb = new StringBuffer(128); //create string buffer
for (int i = 0; i < tokens.length; i++) //iterate through filename
{
if(i ==1)
{
context.file_type = tokens; //Get file load name from filename
}
if (i == 7) //get MD5 String
{
globalMap.put("_md5", tokens.substring(0,32));
context.md5_message = (String)globalMap.get("_md5"); //assign file MD5 to context
}
}
context.basename_message = (String)globalMap.get("basename");
context.guid_message = context.basename_message.substring(25,59);
System.out.println("Assigned Contexts from received file");
System.out.println(context.guid_message); //GUID (IN FILENAME)
System.out.println(context.md5_message); //MD5 (IN FILENAME)
System.out.println(context.basename_message); //FILENAME
System.out.println(context.file_type); //TYPE OF LOAD

System.out.println("Actual Values");
System.out.println((String)globalMap.get("md5"));
System.out.println(((String)globalMap.get("tFileList_1_CURRENT_FILE")));
//(String)globalMap.get("md5") == context.md5_message
if ((String)globalMap.get("md5") == (String)context.md5_message)
{
System.out.println("ITS a MATCH");
}
else
{
System.out.println("Waaaah, waaaah , waaaahh");
}
================================================================================================================
when i compare , the 2 strings above:
if ((String)globalMap.get("md5") == (String)context.md5_message)
it never proves true:
I have pushed my results to screen :
================================================================================================================Assigned Contexts from received file
4f2c2204-9e2f-492a-9c0d-8cd6922a1e
805262c7bd389bc1d0a612f71facce6c //System.out.println(context.md5_message);

20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
EventLoad
Actual Values
805262c7bd389bc1d0a612f71facce6c //System.out.println((String)globalMap.get("md5"));
20120808060022-EventLoad-4f2c2204-9e2f-492a-9c0d-8cd6922a1ef9-805262c7bd389bc1d0a612f71facce6c.txt
Waaaah, waaaah , waaaahh
================================================================================================================
on my output the strings are the same ...
what am i missing ,

I have use equals()

Calling Talend Open Studio Users

The first 100 community members completing the Open Studio survey win a $10 gift voucher.

Start the survey

2019 GARNER MAGIC QUADRANT FOR DATA INTEGRATION TOOL

Talend named a Leader.

Get your copy

OPEN STUDIO FOR DATA INTEGRATION

Kickstart your first data integration and ETL projects.

Download now

What’s New for Talend Summer ’19

Watch the recorded webinar!

Watch Now

Best Practices for Using Context Variables with Talend – Part 4

Pick up some tips and tricks with Context Variables

Blog

How Media Organizations Achieved Success with Data Integration

Learn how media organizations have achieved success with Data Integration

Read

Downloads and Trials

Test drive Talend's enterprise products.

Downloads